diff options
author | Meador Inge <meadori@codesourcery.com> | 2012-10-31 14:58:26 +0000 |
---|---|---|
committer | Meador Inge <meadori@codesourcery.com> | 2012-10-31 14:58:26 +0000 |
commit | e0f1dca1c8c191db3b353b60142a574c2d1c2a54 (patch) | |
tree | 48de2a48d1def1a4030a5f986d7714b089adebc0 /lib/Transforms/Utils/SimplifyLibCalls.cpp | |
parent | 28578661385dc165ffe5171f2b9dad26f0a13cf9 (diff) |
instcombine: Migrate strto* optimizations
This patch migrates the strto* optimizations from the simplify-libcalls
pass into the instcombine library call simplifier.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167119 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/SimplifyLibCalls.cpp')
-rw-r--r-- | lib/Transforms/Utils/SimplifyLibCalls.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp index 1aac8c5745..04e36c4b41 100644 --- a/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -752,6 +752,26 @@ struct StrPBrkOpt : public LibCallOptimization { } }; +struct StrToOpt : public LibCallOptimization { + virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) { + FunctionType *FT = Callee->getFunctionType(); + if ((FT->getNumParams() != 2 && FT->getNumParams() != 3) || + !FT->getParamType(0)->isPointerTy() || + !FT->getParamType(1)->isPointerTy()) + return 0; + + Value *EndPtr = CI->getArgOperand(1); + if (isa<ConstantPointerNull>(EndPtr)) { + // With a null EndPtr, this function won't capture the main argument. + // It would be readonly too, except that it still may write to errno. + CI->addAttribute(1, Attributes::get(Callee->getContext(), + Attributes::NoCapture)); + } + + return 0; + } +}; + } // End anonymous namespace. namespace llvm { @@ -781,6 +801,7 @@ class LibCallSimplifierImpl { StrNCpyOpt StrNCpy; StrLenOpt StrLen; StrPBrkOpt StrPBrk; + StrToOpt StrTo; void initOptimizations(); public: @@ -814,6 +835,13 @@ void LibCallSimplifierImpl::initOptimizations() { Optimizations["strncpy"] = &StrNCpy; Optimizations["strlen"] = &StrLen; Optimizations["strpbrk"] = &StrPBrk; + Optimizations["strtol"] = &StrTo; + Optimizations["strtod"] = &StrTo; + Optimizations["strtof"] = &StrTo; + Optimizations["strtoul"] = &StrTo; + Optimizations["strtoll"] = &StrTo; + Optimizations["strtold"] = &StrTo; + Optimizations["strtoull"] = &StrTo; } Value *LibCallSimplifierImpl::optimizeCall(CallInst *CI) { |