summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
diff options
context:
space:
mode:
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>2015-10-01 22:43:53 +0000
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>2015-10-01 22:43:53 +0000
commitb491a2d641add36f1a2f7674d6b5df038c2d638e (patch)
tree390e86021cf8883cb91294b99ec658b8b215d116 /llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
parentb733f00510e9ea1e737b4efd88516fc47c90e4f1 (diff)
downloadbcm5719-llvm-b491a2d641add36f1a2f7674d6b5df038c2d638e.tar.gz
bcm5719-llvm-b491a2d641add36f1a2f7674d6b5df038c2d638e.zip
[SimplifyLibCalls] Fix instruction misplacement in string/memory libcall optimization
When trying to optimize fortified library functions use the right location to insert new instructions in order to preserve correct def-use order. This fixes an issue where a misplaced instruction definition would happen to be *after* one of its use after a RAUW, forming invalid IR. This behavior was introduced by r227250. Differential Revision: http://reviews.llvm.org/D13301 rdar://problem/22802369 llvm-svn: 249092
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 763e3c05a9d..d5d802ded56 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -2075,13 +2075,17 @@ Value *LibCallSimplifier::optimizeCall(CallInst *CI) {
if (Value *SimplifiedFortifiedCI = FortifiedSimplifier.optimizeCall(CI)) {
// Try to further simplify the result.
CallInst *SimplifiedCI = dyn_cast<CallInst>(SimplifiedFortifiedCI);
- if (SimplifiedCI && SimplifiedCI->getCalledFunction())
- if (Value *V = optimizeStringMemoryLibCall(SimplifiedCI, Builder)) {
+ if (SimplifiedCI && SimplifiedCI->getCalledFunction()) {
+ // 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);
+ if (Value *V = optimizeStringMemoryLibCall(SimplifiedCI, TmpBuilder)) {
// If we were able to further simplify, remove the now redundant call.
SimplifiedCI->replaceAllUsesWith(V);
SimplifiedCI->eraseFromParent();
return V;
}
+ }
return SimplifiedFortifiedCI;
}
OpenPOWER on IntegriCloud