aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
diff options
context:
space:
mode:
authorGeorge Burgess IV <george.burgess.iv@gmail.com>2020-02-04 22:10:39 -0800
committerGeorge Burgess IV <george.burgess.iv@gmail.com>2020-02-08 11:51:00 -0800
commitf8c9ceb1ce9c71574d413a6391812d46d9f9edb3 (patch)
tree5a9b5b8e61707ee1c6014620196f46016547d0b0 /llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
parenta148b9e9909db6a592609eb35b4de38c9e67cb8b (diff)
downloadllvm-f8c9ceb1ce9c71574d413a6391812d46d9f9edb3.zip
llvm-f8c9ceb1ce9c71574d413a6391812d46d9f9edb3.tar.gz
llvm-f8c9ceb1ce9c71574d413a6391812d46d9f9edb3.tar.bz2
[SimplifyLibCalls] Add __strlen_chk.
Bionic has had `__strlen_chk` for a while. Optimizing that into a constant is quite profitable, when possible. Differential Revision: https://reviews.llvm.org/D74079
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index d47e969..c4511c6 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -3093,6 +3093,10 @@ Value *LibCallSimplifier::optimizeCall(CallInst *CI) {
// Try to further simplify the result.
CallInst *SimplifiedCI = dyn_cast<CallInst>(SimplifiedFortifiedCI);
if (SimplifiedCI && SimplifiedCI->getCalledFunction()) {
+ // Ensure that SimplifiedCI's uses are complete, since some calls have
+ // their uses analyzed.
+ replaceAllUsesWith(CI, SimplifiedCI);
+
// Use an IR Builder from SimplifiedCI if available instead of CI
// to guarantee we reach all uses we might replace later on.
IRBuilder<> TmpBuilder(SimplifiedCI);
@@ -3354,6 +3358,14 @@ Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(CallInst *CI,
return Ret;
}
+Value *FortifiedLibCallSimplifier::optimizeStrLenChk(CallInst *CI,
+ IRBuilder<> &B) {
+ if (isFortifiedCallFoldable(CI, 1, None, 0))
+ return emitStrLen(CI->getArgOperand(0), B, CI->getModule()->getDataLayout(),
+ TLI);
+ return nullptr;
+}
+
Value *FortifiedLibCallSimplifier::optimizeStrpNCpyChk(CallInst *CI,
IRBuilder<> &B,
LibFunc Func) {
@@ -3494,6 +3506,8 @@ Value *FortifiedLibCallSimplifier::optimizeCall(CallInst *CI) {
case LibFunc_stpcpy_chk:
case LibFunc_strcpy_chk:
return optimizeStrpCpyChk(CI, Builder, Func);
+ case LibFunc_strlen_chk:
+ return optimizeStrLenChk(CI, Builder);
case LibFunc_stpncpy_chk:
case LibFunc_strncpy_chk:
return optimizeStrpNCpyChk(CI, Builder, Func);