<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi<div><br></div><div>a few places invoke dead instruction removal, but assume only one instruction gets removed. This patch </div><div>resets the iterators when dead instructions have been removed.</div><div><br></div><div>Gerolf</div><div><br></div><div><br></div><div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 189, 38);">Index: lib/Transforms/Scalar/LoopInstSimplify.cpp</div><div style="margin: 0px; font-family: Menlo;">===================================================================</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 189, 38);">--- lib/Transforms/Scalar/LoopInstSimplify.cpp  (revision 206487)</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 189, 38);">+++ lib/Transforms/Scalar/LoopInstSimplify.cpp  (working copy)</div><div style="margin: 0px; font-family: Menlo; color: rgb(206, 121, 36);">@@ -126,7 +126,15 @@</div><div style="margin: 0px; font-family: Menlo;">             ++NumSimplified;</div><div style="margin: 0px; font-family: Menlo;">           }</div><div style="margin: 0px; font-family: Menlo;">         }</div><div style="margin: 0px; font-family: Menlo; color: rgb(213, 59, 211);">-        LocalChanged |= RecursivelyDeleteTriviallyDeadInstructions(I, TLI);</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+        bool res = RecursivelyDeleteTriviallyDeadInstructions(I, TLI);</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+        if (res) {</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+          // RecursivelyDeleteTriviallyDeadInstruction can remove</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+          // more than one instruction, so simply incrementing the</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+          // iterator does not work. When instructions get deleted</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+          // re-iterate instead.</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+          BI = BB->begin(); BE = BB->end();</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+          LocalChanged |= res;</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+        }</div><p style="margin: 0px; font-family: Menlo; background-color: rgb(175, 95, 0); min-height: 21px;"> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-family: Menlo;">         if (IsSubloopHeader && !isa<PHINode>(I))</div><div style="margin: 0px; font-family: Menlo;">           break;</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 189, 38);">Index: lib/Transforms/Utils/SimplifyInstructions.cpp</div><div style="margin: 0px; font-family: Menlo;">===================================================================</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 189, 38);">--- lib/Transforms/Utils/SimplifyInstructions.cpp       (revision 206487)</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 189, 38);">+++ lib/Transforms/Utils/SimplifyInstructions.cpp       (working copy)</div><div style="margin: 0px; font-family: Menlo; color: rgb(206, 121, 36);">@@ -75,7 +75,15 @@</div><div style="margin: 0px; font-family: Menlo;">                 ++NumSimplified;</div><div style="margin: 0px; font-family: Menlo;">                 Changed = true;</div><div style="margin: 0px; font-family: Menlo;">               }</div><div style="margin: 0px; font-family: Menlo; color: rgb(213, 59, 211);">-            Changed |= RecursivelyDeleteTriviallyDeadInstructions(I, TLI);</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+            bool res = RecursivelyDeleteTriviallyDeadInstructions(I, TLI);</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+            if (res)  {</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+              // RecursivelyDeleteTriviallyDeadInstruction can remove</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+              // more than one instruction, so simply incrementing the</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+              // iterator does not work. When instructions get deleted</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+              // re-iterate instead.</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+              BI = BB->begin(); BE = BB->end();</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+              Changed |= res;</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 187, 199);">+            }</div><div style="margin: 0px; font-family: Menlo;">           }</div><p style="margin: 0px; font-family: Menlo; background-color: rgb(175, 95, 0); min-height: 21px;"> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-family: Menlo;">         // Place the list of instructions to simplify on the next loop iteration</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 189, 38);"><div style="margin: 0px;">Index: test/Transforms/InstSimplify/dead-code-removal.ll</div><div style="margin: 0px;">===================================================================</div><div style="margin: 0px;">--- test/Transforms/InstSimplify/dead-code-removal.ll   (revision 0)</div><div style="margin: 0px;">+++ test/Transforms/InstSimplify/dead-code-removal.ll   (working copy)</div><div style="margin: 0px; color: rgb(206, 121, 36);">@@ -0,0 +1,15 @@</div><div style="margin: 0px; color: rgb(52, 187, 199);">+; RUN: opts -instsimplify -S < %s | FileCheck %s</div><div style="margin: 0px; color: rgb(52, 187, 199);">+</div><div style="margin: 0px; color: rgb(52, 187, 199);">+define void @foo() nounwind {</div><div style="margin: 0px; color: rgb(52, 187, 199);">+  br i1 undef, label %1, label %4</div><div style="margin: 0px; color: rgb(52, 187, 199);">+</div><div style="margin: 0px; color: rgb(52, 187, 199);">+; <label>:1                                       ; preds = %1, %0</div><div style="margin: 0px; color: rgb(52, 187, 199);">+; CHECK-NOT: phi</div><div style="margin: 0px; color: rgb(52, 187, 199);">+; CHECK-NOT: sub</div><div style="margin: 0px; color: rgb(52, 187, 199);">+  %2 = phi i32 [ %3, %1 ], [ undef, %0 ]</div><div style="margin: 0px; color: rgb(52, 187, 199);">+  %3 = sub i32 0, undef</div><div style="margin: 0px; color: rgb(52, 187, 199);">+  br label %1</div><div style="margin: 0px; color: rgb(52, 187, 199);">+</div><div style="margin: 0px; color: rgb(52, 187, 199);">+; <label>:4                                       ; preds = %0</div><div style="margin: 0px; color: rgb(52, 187, 199);">+  ret void</div><div style="margin: 0px; color: rgb(52, 187, 199);">+}</div><div><br></div></div></div></body></html>