[llvm] r207309 - RecursivelyDeleteTriviallyDeadInstructions() could remove
Gerolf Hoflehner
ghoflehner at apple.com
Fri Apr 25 22:58:12 PDT 2014
Author: ghoflehner
Date: Sat Apr 26 00:58:11 2014
New Revision: 207309
URL: http://llvm.org/viewvc/llvm-project?rev=207309&view=rev
Log:
RecursivelyDeleteTriviallyDeadInstructions() could remove
more than 1 instruction. The caller need to be aware of this
and adjust instruction iterators accordingly.
rdar://16679376
Repaired r207302.
Added:
llvm/trunk/test/Transforms/InstSimplify/dead-code-removal.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp
llvm/trunk/lib/Transforms/Utils/SimplifyInstructions.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp?rev=207309&r1=207308&r2=207309&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp Sat Apr 26 00:58:11 2014
@@ -127,7 +127,15 @@ bool LoopInstSimplify::runOnLoop(Loop *L
++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;
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyInstructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyInstructions.cpp?rev=207309&r1=207308&r2=207309&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyInstructions.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyInstructions.cpp Sat Apr 26 00:58:11 2014
@@ -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
Added: llvm/trunk/test/Transforms/InstSimplify/dead-code-removal.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/dead-code-removal.ll?rev=207309&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/dead-code-removal.ll (added)
+++ llvm/trunk/test/Transforms/InstSimplify/dead-code-removal.ll Sat Apr 26 00:58:11 2014
@@ -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
+}
More information about the llvm-commits
mailing list