Fix Transforms/SimplifyCFG/2006-02-17-InfiniteUnroll.ll
authorChris Lattner <sabre@nondot.org>
Sat, 18 Feb 2006 00:33:17 +0000 (00:33 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 18 Feb 2006 00:33:17 +0000 (00:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26275 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/SimplifyCFG.cpp

index 1159cd36f5eccab7018b10b28912031929c8e764..3c6c02f7e992f2acab234098f2d68071b2ecf1fe 100644 (file)
@@ -1426,8 +1426,8 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
                   PBI->setSuccessor(1, OldTrue);
                 }
 
-                if (PBI->getSuccessor(0) == TrueDest ||
-                    PBI->getSuccessor(1) == FalseDest) {
+                if ((PBI->getSuccessor(0) == TrueDest && FalseDest != BB) ||
+                    (PBI->getSuccessor(1) == FalseDest && TrueDest != BB)) {
                   // Clone Cond into the predecessor basic block, and or/and the
                   // two conditions together.
                   Instruction *New = Cond->clone();
@@ -1512,6 +1512,12 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
                 PBIOp = BIOp = -1;
               }
               
+              // Check to make sure that the other destination of this branch
+              // isn't BB itself.  If so, this is an infinite loop that will
+              // keep getting unwound.
+              if (PBIOp != -1 && PBI->getSuccessor(PBIOp) == BB)
+                PBIOp = BIOp = -1;
+              
               // Finally, if everything is ok, fold the branches to logical ops.
               if (PBIOp != -1) {
                 BasicBlock *CommonDest = PBI->getSuccessor(PBIOp);