instcombine: Migrate isascii optimizations

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168579 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Meador Inge
2012-11-26 03:10:07 +00:00
parent a0798ec377
commit 017bb750ab
3 changed files with 49 additions and 20 deletions
+17
View File
@@ -1283,6 +1283,21 @@ struct IsDigitOpt : public LibCallOptimization {
}
};
struct IsAsciiOpt : public LibCallOptimization {
virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
FunctionType *FT = Callee->getFunctionType();
// We require integer(i32)
if (FT->getNumParams() != 1 || !FT->getReturnType()->isIntegerTy() ||
!FT->getParamType(0)->isIntegerTy(32))
return 0;
// isascii(c) -> c <u 128
Value *Op = CI->getArgOperand(0);
Op = B.CreateICmpULT(Op, B.getInt32(128), "isascii");
return B.CreateZExt(Op, CI->getType());
}
};
} // End anonymous namespace.
namespace llvm {
@@ -1333,6 +1348,7 @@ class LibCallSimplifierImpl {
FFSOpt FFS;
AbsOpt Abs;
IsDigitOpt IsDigit;
IsAsciiOpt IsAscii;
void initOptimizations();
void addOpt(LibFunc::Func F, LibCallOptimization* Opt);
@@ -1452,6 +1468,7 @@ void LibCallSimplifierImpl::initOptimizations() {
addOpt(LibFunc::labs, &Abs);
addOpt(LibFunc::llabs, &Abs);
addOpt(LibFunc::isdigit, &IsDigit);
addOpt(LibFunc::isascii, &IsAscii);
}
Value *LibCallSimplifierImpl::optimizeCall(CallInst *CI) {