instcombine: Migrate isdigit optimizations

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168578 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Meador Inge
2012-11-26 02:31:59 +00:00
parent d6a93075a1
commit a0798ec377
4 changed files with 67 additions and 42 deletions

View File

@@ -99,25 +99,6 @@ namespace {
// Integer Optimizations
//===----------------------------------------------------------------------===//
//===---------------------------------------===//
// 'isdigit' Optimizations
struct IsDigitOpt : 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;
// isdigit(c) -> (c-'0') <u 10
Value *Op = CI->getArgOperand(0);
Op = B.CreateSub(Op, B.getInt32('0'), "isdigittmp");
Op = B.CreateICmpULT(Op, B.getInt32(10), "isdigit");
return B.CreateZExt(Op, CI->getType());
}
};
//===---------------------------------------===//
// 'isascii' Optimizations
@@ -521,7 +502,7 @@ namespace {
StringMap<LibCallOptimization*> Optimizations;
// Integer Optimizations
IsDigitOpt IsDigit; IsAsciiOpt IsAscii;
IsAsciiOpt IsAscii;
ToAsciiOpt ToAscii;
// Formatting and IO Optimizations
SPrintFOpt SPrintF; PrintFOpt PrintF;
@@ -582,7 +563,6 @@ void SimplifyLibCalls::AddOpt(LibFunc::Func F1, LibFunc::Func F2,
/// we know.
void SimplifyLibCalls::InitOptimizations() {
// Integer Optimizations
Optimizations["isdigit"] = &IsDigit;
Optimizations["isascii"] = &IsAscii;
Optimizations["toascii"] = &ToAscii;