From 1c3ff6595f944c2c9b834895e41c78c9c922f4af Mon Sep 17 00:00:00 2001 From: Andrew Trick Date: Wed, 3 Aug 2011 18:28:21 +0000 Subject: whitespace git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136795 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/LoopSimplify.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/Transforms/Utils/LoopSimplify.cpp') diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index e79fb5a..9af338e 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -213,7 +213,7 @@ ReprocessLoop: // predecessors from outside of the loop, split the edge now. SmallVector ExitBlocks; L->getExitBlocks(ExitBlocks); - + SmallSetVector ExitBlockSet(ExitBlocks.begin(), ExitBlocks.end()); for (SmallSetVector::iterator I = ExitBlockSet.begin(), @@ -402,7 +402,7 @@ BasicBlock *LoopSimplify::RewriteLoopExitBlock(Loop *L, BasicBlock *Exit) { } assert(!LoopBlocks.empty() && "No edges coming in from outside the loop?"); - BasicBlock *NewBB = SplitBlockPredecessors(Exit, &LoopBlocks[0], + BasicBlock *NewBB = SplitBlockPredecessors(Exit, &LoopBlocks[0], LoopBlocks.size(), ".loopexit", this); @@ -467,23 +467,23 @@ void LoopSimplify::PlaceSplitBlockCarefully(BasicBlock *NewBB, if (&*BBI == SplitPreds[i]) return; } - + // If it isn't already after an outside block, move it after one. This is // always good as it makes the uncond branch from the outside block into a // fall-through. - + // Figure out *which* outside block to put this after. Prefer an outside // block that neighbors a BB actually in the loop. BasicBlock *FoundBB = 0; for (unsigned i = 0, e = SplitPreds.size(); i != e; ++i) { Function::iterator BBI = SplitPreds[i]; - if (++BBI != NewBB->getParent()->end() && + if (++BBI != NewBB->getParent()->end() && L->contains(BBI)) { FoundBB = SplitPreds[i]; break; } } - + // If our heuristic for a *good* bb to place this after doesn't find // anything, just pick something. It's likely better than leaving it within // the loop. @@ -544,7 +544,7 @@ Loop *LoopSimplify::SeparateNestedLoop(Loop *L, LPPassManager &LPM) { // Make sure that NewBB is put someplace intelligent, which doesn't mess up // code layout too horribly. PlaceSplitBlockCarefully(NewBB, OuterLoopPreds, L); - + // Create the new outer loop. Loop *NewOuter = new Loop(); -- cgit v1.1 From 1009c3299be8c147ecd3fbd2d75ba1bafb2c84b1 Mon Sep 17 00:00:00 2001 From: Andrew Trick Date: Wed, 3 Aug 2011 18:32:11 +0000 Subject: SCEV: Use AssertingVH to catch dangling BasicBlock* when passes forget to notify SCEV of a change. Add forgetLoop in a couple of those places. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136797 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/LoopSimplify.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/Transforms/Utils/LoopSimplify.cpp') diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index 9af338e..9b16c7cb 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -325,6 +325,14 @@ ReprocessLoop: DEBUG(dbgs() << "LoopSimplify: Eliminating exiting block " << ExitingBlock->getName() << "\n"); + // If any reachable control flow within this loop has changed, notify + // ScalarEvolution. Currently assume the parent loop doesn't change + // (spliting edges doesn't count). If blocks, CFG edges, or other values + // in the parent loop change, then we need call to forgetLoop() for the + // parent instead. + if (SE) + SE->forgetLoop(L); + assert(pred_begin(ExitingBlock) == pred_end(ExitingBlock)); Changed = true; LI->removeBlock(ExitingBlock); -- cgit v1.1 From 1f6a329f79b3568d379142f921f59c4143ddaa14 Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Fri, 12 Aug 2011 14:54:45 +0000 Subject: Silence a bunch (but not all) "variable written but not read" warnings when building with assertions disabled. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@137460 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/LoopSimplify.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/Transforms/Utils/LoopSimplify.cpp') diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index 9b16c7cb..6a99769 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -743,6 +743,7 @@ void LoopSimplify::verifyAnalysis() const { } assert(HasIndBrPred && "LoopSimplify has no excuse for missing loop header info!"); + (void)HasIndBrPred; } // Indirectbr can interfere with exit block canonicalization. @@ -757,5 +758,6 @@ void LoopSimplify::verifyAnalysis() const { } assert(HasIndBrExiting && "LoopSimplify has no excuse for missing exit block info!"); + (void)HasIndBrExiting; } } -- cgit v1.1 From 0906a7c46cfc71e7c09dd6362df4310e72fdbc6b Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 17 Aug 2011 21:20:43 +0000 Subject: 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@137871 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/LoopSimplify.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'lib/Transforms/Utils/LoopSimplify.cpp') diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index 6a99769..b019684 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -398,6 +398,9 @@ BasicBlock *LoopSimplify::InsertPreheaderForLoop(Loop *L) { /// 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 LoopBlocks; for (pred_iterator I = pred_begin(Exit), E = pred_end(Exit); I != E; ++I) { BasicBlock *P = *I; @@ -746,18 +749,29 @@ void LoopSimplify::verifyAnalysis() const { (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 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((ExitingBlocks[i])->getTerminator())) { HasIndBrExiting = true; break; } - assert(HasIndBrExiting && + if (const InvokeInst *II = + dyn_cast(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; } } -- cgit v1.1 From 66af89f642628c0d52138e86f9e4a0b9f5994474 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 18 Aug 2011 21:10:01 +0000 Subject: Revert r137871. The loop simplify pass should require all exits from a loop that aren't from an indirect branch need to be dominated by the loop header. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@137981 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/LoopSimplify.cpp | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'lib/Transforms/Utils/LoopSimplify.cpp') diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index b019684..46bdf57 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -398,9 +398,6 @@ BasicBlock *LoopSimplify::InsertPreheaderForLoop(Loop *L) { /// 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 LoopBlocks; for (pred_iterator I = pred_begin(Exit), E = pred_end(Exit); I != E; ++I) { BasicBlock *P = *I; @@ -749,10 +746,9 @@ void LoopSimplify::verifyAnalysis() const { (void)HasIndBrPred; } - // Indirectbr and LandingPad can interfere with exit block canonicalization. + // Indirectbr can interfere with exit block canonicalization. if (!L->hasDedicatedExits()) { bool HasIndBrExiting = false; - bool HasLPadExiting = false; SmallVector ExitingBlocks; L->getExitingBlocks(ExitingBlocks); for (unsigned i = 0, e = ExitingBlocks.size(); i != e; ++i) { @@ -760,18 +756,10 @@ void LoopSimplify::verifyAnalysis() const { HasIndBrExiting = true; break; } - if (const InvokeInst *II = - dyn_cast(ExitingBlocks[i]->getTerminator())) { - if (L->contains(II->getNormalDest()) && - !L->contains(II->getUnwindDest())) { - HasLPadExiting = true; - break; - } - } } - assert((HasIndBrExiting || HasLPadExiting) && + assert(HasIndBrExiting && "LoopSimplify has no excuse for missing exit block info!"); - (void)HasIndBrExiting; (void)HasLPadExiting; + (void)HasIndBrExiting; } } -- cgit v1.1 From b29ec0642153c4b820d3814d30ddd33e763076f2 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 19 Aug 2011 00:09:22 +0000 Subject: Intelligently split the landing pad block. We have to be careful when splitting the landing pad block, because the landingpad instruction is required to remain as the first non-PHI of an invoke's unwind edge. To retain this, we split the block into two blocks, moving the predecessors within the loop to one block and the remaining predecessors to the other. The landingpad instruction is cloned into the new blocks. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138015 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/LoopSimplify.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'lib/Transforms/Utils/LoopSimplify.cpp') diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index 46bdf57..cbd54a8 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -410,13 +410,24 @@ BasicBlock *LoopSimplify::RewriteLoopExitBlock(Loop *L, BasicBlock *Exit) { } assert(!LoopBlocks.empty() && "No edges coming in from outside the loop?"); - BasicBlock *NewBB = SplitBlockPredecessors(Exit, &LoopBlocks[0], - LoopBlocks.size(), ".loopexit", - this); + BasicBlock *NewExitBB = 0; + + if (Exit->isLandingPad()) { + SmallVector NewBBs; + SplitLandingPadPredecessors(Exit, ArrayRef(&LoopBlocks[0], + LoopBlocks.size()), + ".loopexit", ".nonloopexit", + this, NewBBs); + NewExitBB = NewBBs[0]; + } else { + NewExitBB = SplitBlockPredecessors(Exit, &LoopBlocks[0], + LoopBlocks.size(), ".loopexit", + this); + } DEBUG(dbgs() << "LoopSimplify: Creating dedicated exit block " - << NewBB->getName() << "\n"); - return NewBB; + << NewExitBB->getName() << "\n"); + return NewExitBB; } /// AddBlockAndPredsToSet - Add the specified block, and all of its -- cgit v1.1