RecursivelyDeleteTriviallyDeadInstructions() could remove
[oota-llvm.git] / lib / Transforms / Scalar / LoopInstSimplify.cpp
index a61923cabf1e094ac579a84292ec4bf5fb9b4b62..ab1a9393c526c7c05377945ea4364405544a42ea 100644 (file)
@@ -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;