summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerolf Hoflehner <ghoflehner@apple.com>2014-04-26 05:58:11 +0000
committerGerolf Hoflehner <ghoflehner@apple.com>2014-04-26 05:58:11 +0000
commitaf7a87d2e35138fd6358965f060abaaaa12714c7 (patch)
tree7b047d470d140b12393c43456f3abe55cba001f6
parent1da7cbd584bf4d4c68fdd710adf99e07f93673d7 (diff)
downloadbcm5719-llvm-af7a87d2e35138fd6358965f060abaaaa12714c7.tar.gz
bcm5719-llvm-af7a87d2e35138fd6358965f060abaaaa12714c7.zip
RecursivelyDeleteTriviallyDeadInstructions() could remove
more than 1 instruction. The caller need to be aware of this and adjust instruction iterators accordingly. rdar://16679376 Repaired r207302. llvm-svn: 207309
-rw-r--r--llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp10
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyInstructions.cpp10
-rw-r--r--llvm/test/Transforms/InstSimplify/dead-code-removal.ll15
3 files changed, 33 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp b/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp
index a61923cabf1..ab1a9393c52 100644
--- a/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp
@@ -127,7 +127,15 @@ bool LoopInstSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
++NumSimplified;
}
}
- LocalChanged |= RecursivelyDeleteTriviallyDeadInstructions(I, TLI);
+ bool res = RecursivelyDeleteTriviallyDeadInstructions(I, TLI);
+ if (res) {
+ // RecursivelyDeleteTriviallyDeadInstruction can remove
+ // more than one instruction, so simply incrementing the
+ // iterator does not work. When instructions get deleted
+ // re-iterate instead.
+ BI = BB->begin(); BE = BB->end();
+ LocalChanged |= res;
+ }
if (IsSubloopHeader && !isa<PHINode>(I))
break;
diff --git a/llvm/lib/Transforms/Utils/SimplifyInstructions.cpp b/llvm/lib/Transforms/Utils/SimplifyInstructions.cpp
index c62aa663f6d..33b36378027 100644
--- a/llvm/lib/Transforms/Utils/SimplifyInstructions.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyInstructions.cpp
@@ -76,7 +76,15 @@ namespace {
++NumSimplified;
Changed = true;
}
- Changed |= RecursivelyDeleteTriviallyDeadInstructions(I, TLI);
+ bool res = RecursivelyDeleteTriviallyDeadInstructions(I, TLI);
+ if (res) {
+ // RecursivelyDeleteTriviallyDeadInstruction can remove
+ // more than one instruction, so simply incrementing the
+ // iterator does not work. When instructions get deleted
+ // re-iterate instead.
+ BI = BB->begin(); BE = BB->end();
+ Changed |= res;
+ }
}
// Place the list of instructions to simplify on the next loop iteration
diff --git a/llvm/test/Transforms/InstSimplify/dead-code-removal.ll b/llvm/test/Transforms/InstSimplify/dead-code-removal.ll
new file mode 100644
index 00000000000..e181f3b60d5
--- /dev/null
+++ b/llvm/test/Transforms/InstSimplify/dead-code-removal.ll
@@ -0,0 +1,15 @@
+; RUN: opt -instsimplify -S < %s | FileCheck %s
+
+define void @foo() nounwind {
+ br i1 undef, label %1, label %4
+
+; <label>:1 ; preds = %1, %0
+; CHECK-NOT: phi
+; CHECK-NOT: sub
+ %2 = phi i32 [ %3, %1 ], [ undef, %0 ]
+ %3 = sub i32 0, undef
+ br label %1
+
+; <label>:4 ; preds = %0
+ ret void
+}
OpenPOWER on IntegriCloud