Fix for PR1444: do not create two successors to the same block.
authorDale Johannesen <dalej@apple.com>
Thu, 24 May 2007 17:39:32 +0000 (17:39 +0000)
committerDale Johannesen <dalej@apple.com>
Thu, 24 May 2007 17:39:32 +0000 (17:39 +0000)
Temporarily, this breaks CodeGen/Generic/2006-02-12-InsertLibraryCall.ll
by exposing an unrelated latent problem; working on that.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37323 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/BranchFolding.cpp

index afaaf519524a880d94adc8c2c4db414113f452f5..6c632c2aee3e3e86f1d5c0d81a0f648deec0b68d 100644 (file)
@@ -717,12 +717,20 @@ static void ReplaceUsesOfBlockWith(MachineBasicBlock *BB,
         I->getOperand(i).setMachineBasicBlock(New);
   }
 
-  // Update the successor information.
+  // Update the successor information.  If New was already a successor, just
+  // remove the link to Old instead of creating another one.  PR 1444.
+  bool HadSuccessorNew = false;
   std::vector<MachineBasicBlock*> Succs(BB->succ_begin(), BB->succ_end());
+  for (int i = Succs.size()-1; i >= 0; --i)
+    if (Succs[i] == New) {
+      HadSuccessorNew = true;
+      break;
+    }
   for (int i = Succs.size()-1; i >= 0; --i)
     if (Succs[i] == Old) {
       BB->removeSuccessor(Old);
-      BB->addSuccessor(New);
+      if (!HadSuccessorNew)
+        BB->addSuccessor(New);
     }
 }