aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMeador Inge <meadori@codesourcery.com>2012-11-26 02:31:59 +0000
committerMeador Inge <meadori@codesourcery.com>2012-11-26 02:31:59 +0000
commita0798ec3774de21f3ae3a7eba237e274e4c05ac3 (patch)
tree22dd27e1c5bdc16d8e7053e4245f3e3ea745955c /lib
parentd6a93075a1058072e3b2525d26b3516404a7cef4 (diff)
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
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/SimplifyLibCalls.cpp22
-rw-r--r--lib/Transforms/Utils/SimplifyLibCalls.cpp18
2 files changed, 19 insertions, 21 deletions
diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp
index fecc389307..8ae00d8b3a 100644
--- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp
+++ b/lib/Transforms/Scalar/SimplifyLibCalls.cpp
@@ -100,25 +100,6 @@ namespace {
//===----------------------------------------------------------------------===//
//===---------------------------------------===//
-// '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
struct IsAsciiOpt : public LibCallOptimization {
@@ -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;
diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp
index ec98e93b29..1320f70097 100644
--- a/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1267,6 +1267,22 @@ struct AbsOpt : public LibCallOptimization {
}
};
+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());
+ }
+};
+
} // End anonymous namespace.
namespace llvm {
@@ -1316,6 +1332,7 @@ class LibCallSimplifierImpl {
// Integer library call optimizations.
FFSOpt FFS;
AbsOpt Abs;
+ IsDigitOpt IsDigit;
void initOptimizations();
void addOpt(LibFunc::Func F, LibCallOptimization* Opt);
@@ -1434,6 +1451,7 @@ void LibCallSimplifierImpl::initOptimizations() {
addOpt(LibFunc::abs, &Abs);
addOpt(LibFunc::labs, &Abs);
addOpt(LibFunc::llabs, &Abs);
+ addOpt(LibFunc::isdigit, &IsDigit);
}
Value *LibCallSimplifierImpl::optimizeCall(CallInst *CI) {