[PATCH] reset iterators when more than one dead code instruction is removed
Gerolf Hoflehner
ghoflehner at apple.com
Thu Apr 24 17:22:53 PDT 2014
Hi
a few places invoke dead instruction removal, but assume only one instruction gets removed. This patch
resets the iterators when dead instructions have been removed.
Gerolf
Index: lib/Transforms/Scalar/LoopInstSimplify.cpp
===================================================================
--- lib/Transforms/Scalar/LoopInstSimplify.cpp (revision 206487)
+++ lib/Transforms/Scalar/LoopInstSimplify.cpp (working copy)
@@ -126,7 +126,15 @@
++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;
Index: lib/Transforms/Utils/SimplifyInstructions.cpp
===================================================================
--- lib/Transforms/Utils/SimplifyInstructions.cpp (revision 206487)
+++ lib/Transforms/Utils/SimplifyInstructions.cpp (working copy)
@@ -75,7 +75,15 @@
++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
Index: test/Transforms/InstSimplify/dead-code-removal.ll
===================================================================
--- test/Transforms/InstSimplify/dead-code-removal.ll (revision 0)
+++ test/Transforms/InstSimplify/dead-code-removal.ll (working copy)
@@ -0,0 +1,15 @@
+; RUN: opts -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
+}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140424/496baed7/attachment.html>
More information about the llvm-commits
mailing list