instcombine: Migrate toascii optimizations

This patch migrates the toascii optimizations from the simplify-libcalls
pass into the instcombine library call simplifier.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168580 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Meador Inge
2012-11-26 03:38:52 +00:00
parent 017bb750ab
commit 38c4441797
4 changed files with 75 additions and 47 deletions

View File

@ -1298,6 +1298,20 @@ struct IsAsciiOpt : public LibCallOptimization {
}
};
struct ToAsciiOpt : public LibCallOptimization {
virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
FunctionType *FT = Callee->getFunctionType();
// We require i32(i32)
if (FT->getNumParams() != 1 || FT->getReturnType() != FT->getParamType(0) ||
!FT->getParamType(0)->isIntegerTy(32))
return 0;
// isascii(c) -> c & 0x7f
return B.CreateAnd(CI->getArgOperand(0),
ConstantInt::get(CI->getType(),0x7F));
}
};
} // End anonymous namespace.
namespace llvm {
@ -1349,6 +1363,7 @@ class LibCallSimplifierImpl {
AbsOpt Abs;
IsDigitOpt IsDigit;
IsAsciiOpt IsAscii;
ToAsciiOpt ToAscii;
void initOptimizations();
void addOpt(LibFunc::Func F, LibCallOptimization* Opt);
@ -1469,6 +1484,7 @@ void LibCallSimplifierImpl::initOptimizations() {
addOpt(LibFunc::llabs, &Abs);
addOpt(LibFunc::isdigit, &IsDigit);
addOpt(LibFunc::isascii, &IsAscii);
addOpt(LibFunc::toascii, &ToAscii);
}
Value *LibCallSimplifierImpl::optimizeCall(CallInst *CI) {