RecursivelyDeleteTriviallyDeadInstructions() could remove
[oota-llvm.git] / lib / Transforms / Utils / SimplifyInstructions.cpp
index c62aa663f6d0efaff465cc666f9ceae6bc45c594..33b36378027d01715456f9b9382e62225e142eac 100644 (file)
@@ -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