From 25cae0fd1ca1be2dc4b10864e0f7c8fc86ecd51d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 18 Feb 2006 00:55:32 +0000 Subject: [PATCH] When unswitching a loop, make sure to update loop info with exit blocks in the right loop. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26277 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopUnswitch.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 6d29090ccb7..6add98d1ce5 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -590,6 +590,7 @@ void LoopUnswitch::VersionLoop(Value *LIC, Constant *Val, Loop *L, // Split all of the edges from inside the loop to their exit blocks. This // unswitching trivial: no phi nodes to update. unsigned NumBlocks = L->getBlocks().size(); + for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) { BasicBlock *ExitBlock = ExitBlocks[i]; std::vector Preds(pred_begin(ExitBlock), pred_end(ExitBlock)); @@ -639,8 +640,9 @@ void LoopUnswitch::VersionLoop(Value *LIC, Constant *Val, Loop *L, for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) { BasicBlock *NewExit = cast(ValueMap[ExitBlocks[i]]); - if (ParentLoop) - ParentLoop->addBasicBlockToLoop(cast(NewExit), *LI); + // The new exit block should be in the same loop as the old one. + if (Loop *ExitBBLoop = LI->getLoopFor(ExitBlocks[i])) + ExitBBLoop->addBasicBlockToLoop(NewExit, *LI); assert(NewExit->getTerminator()->getNumSuccessors() == 1 && "Exit block should have been split to have one successor!");