From 7f2e1dd5d42a4411e5d4c89297952325239b4c2a Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 12 Jun 2006 20:18:01 +0000 Subject: [PATCH] Fix an infinite loop on Transforms/SimplifyCFG/2006-06-12-InfLoop.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28758 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/SimplifyCFG.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index ecd1471b4e3..8f7a154cf48 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1515,12 +1515,21 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { // 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); BasicBlock *OtherDest = BI->getSuccessor(BIOp ^ 1); + // If OtherDest *is* BB, then this is a basic block with just + // a conditional branch in it, where one edge (OtherDesg) goes + // back to the block. We know that the program doesn't get + // stuck in the infinite loop, so the condition must be such + // that OtherDest isn't branched through. Forward to CommonDest, + // and avoid an infinite loop at optimizer time. + if (OtherDest == BB) + OtherDest = CommonDest; + DEBUG(std::cerr << "FOLDING BRs:" << *PBI->getParent() << "AND: " << *BI->getParent()); -- 2.11.0