aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/LoopSimplify.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-02-11 21:24:54 +0000
committerChris Lattner <sabre@nondot.org>2006-02-11 21:24:54 +0000
commitd308ddcd67f1e8acc4973186300fba927061ef32 (patch)
treedd8af8b3a05e55980e363d9fa3fd62ff60fa73fb /lib/Transforms/Utils/LoopSimplify.cpp
parent539c3371483bd62fc01bedc7f7977e39e356ef32 (diff)
Fix for my previously reverted patch
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26126 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/LoopSimplify.cpp')
-rw-r--r--lib/Transforms/Utils/LoopSimplify.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp
index a8aa0e0bbc..488915e96e 100644
--- a/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/lib/Transforms/Utils/LoopSimplify.cpp
@@ -156,12 +156,18 @@ bool LoopSimplify::ProcessLoop(Loop *L) {
// Next, check to make sure that all exit nodes of the loop only have
// predecessors that are inside of the loop. This check guarantees that the
// loop preheader/header will dominate the exit blocks. If the exit block has
- // predecessors from outside of the loop, split the edge now.
- std::vector<BasicBlock*> ExitBlocks;
- L->getExitBlocks(ExitBlocks);
-
- SetVector<BasicBlock*> ExitBlockSet(ExitBlocks.begin(), ExitBlocks.end());
+ // predecessors from outside of the loop, split the edge now. Note that we
+ // only want to consider the exit blocks of *this* loop, not of any subloops,
+ // so we can't use Loop::getExitBlocks().
LoopInfo &LI = getAnalysis<LoopInfo>();
+ SetVector<BasicBlock*> ExitBlockSet;
+ for (Loop::block_iterator BI = L->block_begin(),
+ BE = L->block_end(); BI != BE; ++BI)
+ if (LI.getLoopFor(*BI) == L) // not a subloop.
+ for (succ_iterator I = succ_begin(*BI), E = succ_end(*BI); I != E; ++I)
+ if (!L->contains(*I)) // Not in current loop?
+ ExitBlockSet.insert(*I); // It must be an exit block.
+
for (SetVector<BasicBlock*>::iterator I = ExitBlockSet.begin(),
E = ExitBlockSet.end(); I != E; ++I) {
BasicBlock *ExitBlock = *I;
@@ -169,7 +175,7 @@ bool LoopSimplify::ProcessLoop(Loop *L) {
PI != PE; ++PI)
// Must be exactly this loop: no subloops, parent loops, or non-loop preds
// allowed.
- if (!L->contains(*PI)) {
+ if (LI.getLoopFor(*PI) != L) {
RewriteLoopExitBlock(L, ExitBlock);
NumInserted++;
Changed = true;