From 9f879cfb0a93bf34818fb68e1dc209d47a7d24f3 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 27 Feb 2003 22:48:57 +0000 Subject: [PATCH] Fix bug: 2003-02-27-PreheaderExitNodeUpdate.ll by updating exit node info git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5664 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/LoopSimplify.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index e40f1457ae4..c5adfd25534 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -192,6 +192,22 @@ void Preheaders::InsertPreheaderForLoop(Loop *L) { // We know that we have loop information to update... update it now. if (Loop *Parent = L->getParentLoop()) Parent->addBasicBlockToLoop(NewBB, getAnalysis()); + + // If the header for the loop used to be an exit node for another loop, then + // we need to update this to know that the loop-preheader is now the exit + // node. Note that the only loop that could have our header as an exit node + // is a sibling loop, ie, one with the same parent loop. + const std::vector *ParentSubLoops; + if (Loop *Parent = L->getParentLoop()) + ParentSubLoops = &Parent->getSubLoops(); + else // Must check top-level loops... + ParentSubLoops = &getAnalysis().getTopLevelLoops(); + + // Loop over all sibling loops, performing the substitution... + for (unsigned i = 0, e = ParentSubLoops->size(); i != e; ++i) + if ((*ParentSubLoops)[i]->hasExitBlock(Header)) + (*ParentSubLoops)[i]->changeExitBlock(Header, NewBB); + DominatorSet &DS = getAnalysis(); // Update dominator info {