[llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopUnswitch.cpp
Devang Patel
dpatel at apple.com
Wed May 9 01:24:30 PDT 2007
Changes in directory llvm/lib/Transforms/Scalar:
LoopUnswitch.cpp updated: 1.68 -> 1.69
---
Log message:
Fix PR1333: http://llvm.org/PR1333
Testcases :
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070507/049451.html
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070507/049452.html
---
Diffs of the changes: (+25 -5)
LoopUnswitch.cpp | 30 +++++++++++++++++++++++++-----
1 files changed, 25 insertions(+), 5 deletions(-)
Index: llvm/lib/Transforms/Scalar/LoopUnswitch.cpp
diff -u llvm/lib/Transforms/Scalar/LoopUnswitch.cpp:1.68 llvm/lib/Transforms/Scalar/LoopUnswitch.cpp:1.69
--- llvm/lib/Transforms/Scalar/LoopUnswitch.cpp:1.68 Wed May 2 20:11:54 2007
+++ llvm/lib/Transforms/Scalar/LoopUnswitch.cpp Wed May 9 03:24:12 2007
@@ -396,7 +396,7 @@
// The new block lives in whichever loop the old one did.
if (Loop *L = LI->getLoopFor(Old))
L->addBasicBlockToLoop(New, *LI);
-
+
return New;
}
@@ -413,8 +413,30 @@
}
// If this is a critical edge, let SplitCriticalEdge do it.
- if (SplitCriticalEdge(BB->getTerminator(), SuccNum, this))
- return LatchTerm->getSuccessor(SuccNum);
+ Loop *OrigDestBBL = LI->getLoopFor(BB->getTerminator()->getSuccessor(SuccNum));
+ if (SplitCriticalEdge(BB->getTerminator(), SuccNum)) {
+ BasicBlock *NewBB = LatchTerm->getSuccessor(SuccNum);
+
+ Loop *BBL = LI->getLoopFor(BB);
+ if (!BBL || !OrigDestBBL)
+ return NewBB;
+
+ // If edge is inside a loop then NewBB is part of same loop.
+ if (BBL == OrigDestBBL)
+ BBL->addBasicBlockToLoop(NewBB, *LI);
+ // If edge is entering loop then NewBB is part of outer loop.
+ else if (BBL->contains(OrigDestBBL->getHeader()))
+ BBL->addBasicBlockToLoop(NewBB, *LI);
+ // If edge is from an inner loop to outer loop then NewBB is part
+ // of outer loop.
+ else if (OrigDestBBL->contains(BBL->getHeader()))
+ OrigDestBBL->addBasicBlockToLoop(NewBB, *LI);
+ // Else edge is connecting two loops and NewBB is part of their parent loop
+ else if (Loop *PL = OrigDestBBL->getParentLoop())
+ PL->addBasicBlockToLoop(NewBB, *LI);
+
+ return NewBB;
+ }
// If the edge isn't critical, then BB has a single successor or Succ has a
// single pred. Split the block.
@@ -571,8 +593,6 @@
std::vector<BasicBlock*> Preds(pred_begin(ExitBlock), pred_end(ExitBlock));
for (unsigned j = 0, e = Preds.size(); j != e; ++j) {
- assert(L->contains(Preds[j]) &&
- "All preds of loop exit blocks must be the same loop!");
BasicBlock* MiddleBlock = SplitEdge(Preds[j], ExitBlock);
BasicBlock* StartBlock = Preds[j];
BasicBlock* EndBlock;
More information about the llvm-commits
mailing list