fix PR5640 by tracking whether a block is the header of a loop more
authorChris Lattner <sabre@nondot.org>
Tue, 1 Dec 2009 06:04:43 +0000 (06:04 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 1 Dec 2009 06:04:43 +0000 (06:04 +0000)
precisely, which prevents us from infinitely peeling the loop.

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

lib/Transforms/Scalar/JumpThreading.cpp
test/Transforms/JumpThreading/crash.ll

index 58641135ede83591825237bd7ef749f9d1e61376..1b93f3441e4131df87eabd549d96f8952c292c96 100644 (file)
@@ -158,12 +158,18 @@ bool JumpThreading::runOnFunction(Function &F) {
           if (BBI->isTerminator()) {
             // Since TryToSimplifyUncondBranchFromEmptyBlock may delete the
             // block, we have to make sure it isn't in the LoopHeaders set.  We
-            // reinsert afterward in the rare case when the block isn't deleted.
+            // reinsert afterward if needed.
             bool ErasedFromLoopHeaders = LoopHeaders.erase(BB);
+            BasicBlock *Succ = BI->getSuccessor(0);
             
-            if (TryToSimplifyUncondBranchFromEmptyBlock(BB))
+            if (TryToSimplifyUncondBranchFromEmptyBlock(BB)) {
               Changed = true;
-            else if (ErasedFromLoopHeaders)
+              // If we deleted BB and BB was the header of a loop, then the
+              // successor is now the header of the loop.
+              BB = Succ;
+            }
+            
+            if (ErasedFromLoopHeaders)
               LoopHeaders.insert(BB);
           }
         }
index 7e2a2a047d111e74beb52018cf3bc112c9fc62ba..b2b9d69e16d2fcfa0db6dc0df0f60ee7d6f9028d 100644 (file)
@@ -192,3 +192,23 @@ bb61:
   ret void
 }
 
+
+; PR5640
+define fastcc void @test6(i1 %tmp, i1 %tmp1) nounwind ssp {
+entry:
+  br i1 %tmp, label %bb12, label %bb14
+
+bb12:           
+  br label %bb14
+
+bb14:           
+  %A = phi i1 [ %A, %bb13 ],  [ true, %bb12 ], [%tmp1, %entry]
+  br label %bb13
+
+bb13:                                            
+  br i1 %A, label %bb14, label %bb61
+
+
+bb61:                                            
+  ret void
+}