diff --git a/llvm/lib/Transforms/IPO/LoopExtractor.cpp b/llvm/lib/Transforms/IPO/LoopExtractor.cpp index 714282b2b5eb..826ade38d1ea 100644 --- a/llvm/lib/Transforms/IPO/LoopExtractor.cpp +++ b/llvm/lib/Transforms/IPO/LoopExtractor.cpp @@ -101,18 +101,24 @@ bool LoopExtractor::runOnLoop(Loop *L, LPPassManager &LPM) { L->getHeader()->getParent()->getEntryBlock().getTerminator(); if (!isa(EntryTI) || !cast(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 ExitBlocks; L->getExitBlocks(ExitBlocks); - for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) - if (!isa(ExitBlocks[i]->getTerminator())) { + for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) { + if (!isa(ExitBlocks[i]->getTerminator())) ShouldExtractLoop = true; + if (ExitBlocks[i]->isLandingPad()) { + ShouldExtractLoop = false; break; } + } } if (ShouldExtractLoop) { if (NumLoops == 0) return Changed;