Use Duncan's patch to delete the instructions in reverse order (minus the landingpad...
authorBill Wendling <isanbard@gmail.com>
Sun, 4 Sep 2011 09:43:36 +0000 (09:43 +0000)
committerBill Wendling <isanbard@gmail.com>
Sun, 4 Sep 2011 09:43:36 +0000 (09:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139090 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstructionCombining.cpp
lib/Transforms/Scalar/SCCP.cpp

index 51fe2e5a4119802be8f37ee360483f437a795ee5..f64990fe0b4a50eb6fa3020d51fa7e7c1dbb78b1 100644 (file)
@@ -1574,15 +1574,19 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {
     for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
       if (Visited.count(BB)) continue;
 
-      // Delete the instructions.
-      for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
-        Instruction *Inst = &*I++;
-        if (isa<TerminatorInst>(Inst))
-          break;
+      // Delete the instructions backwards, as it has a reduced likelihood of
+      // having to update as many def-use and use-def chains.
+      Instruction *EndInst = BB->getTerminator(); // Last not to be deleted.
+      while (EndInst != BB->begin()) {
+        // Delete the next to last instruction.
+        BasicBlock::iterator I = EndInst;
+        Instruction *Inst = --I;
         if (!Inst->use_empty())
           Inst->replaceAllUsesWith(UndefValue::get(Inst->getType()));
-        if (isa<LandingPadInst>(Inst))
+        if (isa<LandingPadInst>(Inst)) {
+          EndInst = Inst;
           continue;
+        }
         if (!isa<DbgInfoIntrinsic>(Inst)) {
           ++NumDeadInst;
           MadeIRChange = true;
index 0091a3df7d723ac1061d7ad20d2917ffb0405017..02e6b72d3afd13c5240d0df4338ba48bd0ab73d2 100644 (file)
@@ -1686,15 +1686,19 @@ static void DeleteInstructionInBlock(BasicBlock *BB) {
   if (isa<TerminatorInst>(BB->begin()))
     return;
 
-  // Delete the instructions.
-  for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
-    Instruction *Inst = &*I++;
-    if (isa<TerminatorInst>(Inst))
-      break;
+  // Delete the instructions backwards, as it has a reduced likelihood of having
+  // to update as many def-use and use-def chains.
+  Instruction *EndInst = BB->getTerminator(); // Last not to be deleted.
+  while (EndInst != BB->begin()) {
+    // Delete the next to last instruction.
+    BasicBlock::iterator I = EndInst;
+    Instruction *Inst = --I;
     if (!Inst->use_empty())
       Inst->replaceAllUsesWith(UndefValue::get(Inst->getType()));
-    if (isa<LandingPadInst>(Inst))
+    if (isa<LandingPadInst>(Inst)) {
+      EndInst = Inst;
       continue;
+    }
     BB->getInstList().erase(Inst);
     ++NumInstRemoved;
   }