[llvm-commits] [llvm] r137871 - /llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp

Bill Wendling isanbard at gmail.com
Wed Aug 17 14:20:43 PDT 2011


Author: void
Date: Wed Aug 17 16:20:43 2011
New Revision: 137871

URL: http://llvm.org/viewvc/llvm-project?rev=137871&view=rev
Log:
Don't optimize the landing pad exit block.

One way to exit the loop is through an unwind edge. However, that may involve
splitting the critical edge of the landing pad, which is non-trivial. Prevent
the transformation from rewriting the landing pad exit loop block.

Modified:
    llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp

Modified: llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp?rev=137871&r1=137870&r2=137871&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp Wed Aug 17 16:20:43 2011
@@ -398,6 +398,9 @@
 /// blocks.  This method is used to split exit blocks that have predecessors
 /// outside of the loop.
 BasicBlock *LoopSimplify::RewriteLoopExitBlock(Loop *L, BasicBlock *Exit) {
+  // Don't split a landing pad block.
+  if (Exit->isLandingPad()) return 0;
+
   SmallVector<BasicBlock*, 8> LoopBlocks;
   for (pred_iterator I = pred_begin(Exit), E = pred_end(Exit); I != E; ++I) {
     BasicBlock *P = *I;
@@ -746,18 +749,29 @@
     (void)HasIndBrPred;
   }
 
-  // Indirectbr can interfere with exit block canonicalization.
+  // Indirectbr and LandingPad can interfere with exit block canonicalization.
   if (!L->hasDedicatedExits()) {
     bool HasIndBrExiting = false;
+    bool HasLPadExiting = false;
     SmallVector<BasicBlock*, 8> ExitingBlocks;
     L->getExitingBlocks(ExitingBlocks);
-    for (unsigned i = 0, e = ExitingBlocks.size(); i != e; ++i)
+    for (unsigned i = 0, e = ExitingBlocks.size(); i != e; ++i) {
       if (isa<IndirectBrInst>((ExitingBlocks[i])->getTerminator())) {
         HasIndBrExiting = true;
         break;
       }
-    assert(HasIndBrExiting &&
+      if (const InvokeInst *II =
+          dyn_cast<InvokeInst>(ExitingBlocks[i]->getTerminator())) {
+        if (L->contains(II->getNormalDest()) &&
+            !L->contains(II->getUnwindDest())) {
+          HasLPadExiting = true;
+          break;
+        }
+      }
+    }
+
+    assert((HasIndBrExiting || HasLPadExiting) &&
            "LoopSimplify has no excuse for missing exit block info!");
-    (void)HasIndBrExiting;
+    (void)HasIndBrExiting; (void)HasLPadExiting;
   }
 }





More information about the llvm-commits mailing list