When unswitching a loop, make sure to update loop info with exit blocks in
authorChris Lattner <sabre@nondot.org>
Sat, 18 Feb 2006 00:55:32 +0000 (00:55 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 18 Feb 2006 00:55:32 +0000 (00:55 +0000)
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

index 6d29090ccb7014365a3b74678c56574b1a5a88dd..6add98d1ce54e2ea05fde8479d913d820ac6f526 100644 (file)
@@ -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!");