From 46875c0bfb77880ba4120eeed7caca7f1f7c1f69 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 1 Dec 2009 06:04:43 +0000 Subject: [PATCH] fix PR5640 by tracking whether a block is the header of a loop more 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 | 12 +++++++++--- test/Transforms/JumpThreading/crash.ll | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp index 58641135ede..1b93f3441e4 100644 --- a/lib/Transforms/Scalar/JumpThreading.cpp +++ b/lib/Transforms/Scalar/JumpThreading.cpp @@ -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); } } diff --git a/test/Transforms/JumpThreading/crash.ll b/test/Transforms/JumpThreading/crash.ll index 7e2a2a047d1..b2b9d69e16d 100644 --- a/test/Transforms/JumpThreading/crash.ll +++ b/test/Transforms/JumpThreading/crash.ll @@ -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 +}