[llvm-commits] CVS: llvm/lib/Transforms/Utils/LoopSimplify.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Feb 10 18:13:28 PST 2006



Changes in directory llvm/lib/Transforms/Utils:

LoopSimplify.cpp updated: 1.63 -> 1.64
---
Log message:

Make this check stricter.  Disallow loop exit blocks from being shared by
loops and their subloops.


---
Diffs of the changes:  (+7 -4)

 LoopSimplify.cpp |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)


Index: llvm/lib/Transforms/Utils/LoopSimplify.cpp
diff -u llvm/lib/Transforms/Utils/LoopSimplify.cpp:1.63 llvm/lib/Transforms/Utils/LoopSimplify.cpp:1.64
--- llvm/lib/Transforms/Utils/LoopSimplify.cpp:1.63	Fri Feb 10 19:43:37 2006
+++ llvm/lib/Transforms/Utils/LoopSimplify.cpp	Fri Feb 10 20:13:17 2006
@@ -109,7 +109,6 @@
   return Changed;
 }
 
-
 /// ProcessLoop - Walk the loop structure in depth first order, ensuring that
 /// all loops have preheaders.
 ///
@@ -162,12 +161,15 @@
   L->getExitBlocks(ExitBlocks);
 
   SetVector<BasicBlock*> ExitBlockSet(ExitBlocks.begin(), ExitBlocks.end());
+  LoopInfo &LI = getAnalysis<LoopInfo>();
   for (SetVector<BasicBlock*>::iterator I = ExitBlockSet.begin(),
          E = ExitBlockSet.end(); I != E; ++I) {
     BasicBlock *ExitBlock = *I;
     for (pred_iterator PI = pred_begin(ExitBlock), PE = pred_end(ExitBlock);
          PI != PE; ++PI)
-      if (!L->contains(*PI)) {
+      // Must be exactly this loop: no subloops, parent loops, or non-loop preds
+      // allowed.
+      if (LI.getLoopFor(*PI) != L) {
         RewriteLoopExitBlock(L, ExitBlock);
         NumInserted++;
         Changed = true;
@@ -178,6 +180,7 @@
   // If the header has more than two predecessors at this point (from the
   // preheader and from multiple backedges), we must adjust the loop.
   if (L->getNumBackEdges() != 1) {
+    
     // If this is really a nested loop, rip it out into a child loop.
     if (Loop *NL = SeparateNestedLoop(L)) {
       ++NumNested;
@@ -310,8 +313,8 @@
   std::vector<BasicBlock*> OutsideBlocks;
   for (pred_iterator PI = pred_begin(Header), PE = pred_end(Header);
        PI != PE; ++PI)
-      if (!L->contains(*PI))           // Coming in from outside the loop?
-        OutsideBlocks.push_back(*PI);  // Keep track of it...
+    if (!L->contains(*PI))           // Coming in from outside the loop?
+      OutsideBlocks.push_back(*PI);  // Keep track of it...
 
   // Split out the loop pre-header
   BasicBlock *NewBB =






More information about the llvm-commits mailing list