[llvm-commits] [llvm] r84505 - in /llvm/trunk: lib/Transforms/Utils/BasicBlockUtils.cpp test/Transforms/LoopSimplify/unreachable-loop-pred.ll

Dan Gohman gohman at apple.com
Mon Oct 19 09:04:50 PDT 2009


Author: djg
Date: Mon Oct 19 11:04:50 2009
New Revision: 84505

URL: http://llvm.org/viewvc/llvm-project?rev=84505&view=rev
Log:
Fix SplitBlockPredecessors' LoopInfo updating code to handle the case
where a loop's header is being split and it has predecessors which are not
contained by the most-nested loop which contains the loop.
This fixes PR5235.

Added:
    llvm/trunk/test/Transforms/LoopSimplify/unreachable-loop-pred.ll
Modified:
    llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp

Modified: llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp?rev=84505&r1=84504&r2=84505&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp Mon Oct 19 11:04:50 2009
@@ -425,14 +425,26 @@
 
   if (L) {
     if (IsLoopEntry) {
-      if (Loop *PredLoop = LI->getLoopFor(Preds[0])) {
-        // Add the new block to the nearest enclosing loop (and not an
-        // adjacent loop).
-        while (PredLoop && !PredLoop->contains(BB))
-          PredLoop = PredLoop->getParentLoop();
-        if (PredLoop)
-          PredLoop->addBasicBlockToLoop(NewBB, LI->getBase());
-      }
+      // Add the new block to the nearest enclosing loop (and not an
+      // adjacent loop). To find this, examine each of the predecessors and
+      // determine which loops enclose them, and select the most-nested loop
+      // which contains the loop containing the block being split.
+      Loop *InnermostPredLoop = 0;
+      for (unsigned i = 0; i != NumPreds; ++i)
+        if (Loop *PredLoop = LI->getLoopFor(Preds[i])) {
+          // Seek a loop which actually contains the block being split (to
+          // avoid adjacent loops).
+          while (PredLoop && !PredLoop->contains(BB))
+            PredLoop = PredLoop->getParentLoop();
+          // Select the most-nested of these loops which contains the block.
+          if (PredLoop &&
+              PredLoop->contains(BB) &&
+              (!InnermostPredLoop ||
+               InnermostPredLoop->getLoopDepth() < PredLoop->getLoopDepth()))
+            InnermostPredLoop = PredLoop;
+        }
+      if (InnermostPredLoop)
+        InnermostPredLoop->addBasicBlockToLoop(NewBB, LI->getBase());
     } else {
       L->addBasicBlockToLoop(NewBB, LI->getBase());
       if (SplitMakesNewLoopHeader)

Added: llvm/trunk/test/Transforms/LoopSimplify/unreachable-loop-pred.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopSimplify/unreachable-loop-pred.ll?rev=84505&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/LoopSimplify/unreachable-loop-pred.ll (added)
+++ llvm/trunk/test/Transforms/LoopSimplify/unreachable-loop-pred.ll Mon Oct 19 11:04:50 2009
@@ -0,0 +1,20 @@
+; RUN: opt -S -loopsimplify -disable-output -verify-loop-info -verify-dom-info < %s
+; PR5235
+
+; When loopsimplify inserts a preheader for this loop, it should add the new
+; block to the enclosing loop and not get confused by the unreachable
+; bogus loop entry.
+
+define void @is_extract_cab() nounwind {
+entry:
+  br label %header
+
+header:                                       ; preds = %if.end206, %cond.end66, %if.end23
+  br label %while.body115
+
+while.body115:                                    ; preds = %9, %if.end192, %if.end101
+  br i1 undef, label %header, label %while.body115
+
+foo:
+  br label %while.body115
+}





More information about the llvm-commits mailing list