Omit extracting a loop if one of the exits is a landing pad.
authorBill Wendling <isanbard@gmail.com>
Tue, 20 Sep 2011 22:23:09 +0000 (22:23 +0000)
committerBill Wendling <isanbard@gmail.com>
Tue, 20 Sep 2011 22:23:09 +0000 (22:23 +0000)
The landing pad must accompany the invoke when it's extracted. However, if it
does, then the loop isn't properly extracted. I.e., the resulting extraction has
a loop in it. The extracted function is then extracted, etc. resulting in an
infinite loop.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140193 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/LoopExtractor.cpp

index 714282b2b5eb11f8eb24c7a0c6aea2cdf0a60710..826ade38d1ea0e8d106eb8ef3457cb3b0b0d1c02 100644 (file)
@@ -101,18 +101,24 @@ bool LoopExtractor::runOnLoop(Loop *L, LPPassManager &LPM) {
     L->getHeader()->getParent()->getEntryBlock().getTerminator();
   if (!isa<BranchInst>(EntryTI) ||
       !cast<BranchInst>(EntryTI)->isUnconditional() ||
-      EntryTI->getSuccessor(0) != L->getHeader())
+      EntryTI->getSuccessor(0) != L->getHeader()) {
     ShouldExtractLoop = true;
-  else {
+  else {
     // Check to see if any exits from the loop are more than just return
-    // blocks.
+    // blocks. We also must omit landing pads. Landing pads must accompany the
+    // invoke instruction. But this would result in a loop in the extracted
+    // function. An infinite cycle occurs when it tries to extract that loop as
+    // well.
     SmallVector<BasicBlock*, 8> ExitBlocks;
     L->getExitBlocks(ExitBlocks);
-    for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
-      if (!isa<ReturnInst>(ExitBlocks[i]->getTerminator())) {
+    for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
+      if (!isa<ReturnInst>(ExitBlocks[i]->getTerminator()))
         ShouldExtractLoop = true;
+      if (ExitBlocks[i]->isLandingPad()) {
+        ShouldExtractLoop = false;
         break;
       }
+    }
   }
   if (ShouldExtractLoop) {
     if (NumLoops == 0) return Changed;