diff options
Diffstat (limited to 'lib/Transforms/Scalar/LoopUnswitch.cpp')
-rw-r--r-- | lib/Transforms/Scalar/LoopUnswitch.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 6d29090ccb..6add98d1ce 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<BasicBlock*> 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<BasicBlock>(ValueMap[ExitBlocks[i]]); - if (ParentLoop) - ParentLoop->addBasicBlockToLoop(cast<BasicBlock>(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!"); |