diff options
author | Dan Gohman <gohman@apple.com> | 2009-10-19 16:04:50 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-10-19 16:04:50 +0000 |
commit | 8f986672a124bee96d30d7aa9b9ab2b205f37345 (patch) | |
tree | 2ade05886064fbdf879d866b898335a723fd7063 /llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | |
parent | b0db9917afdb1ef5da6ad7d36bfe5fbfc0f43c45 (diff) | |
download | llvm-8f986672a124bee96d30d7aa9b9ab2b205f37345.zip llvm-8f986672a124bee96d30d7aa9b9ab2b205f37345.tar.gz llvm-8f986672a124bee96d30d7aa9b9ab2b205f37345.tar.bz2 |
Fix SplitBlockPredecessors' LoopInfo updating code to handle the case
where a loop's header is being split and it has predecessors which are not
contained by the most-nested loop which contains the loop.
This fixes PR5235.
llvm-svn: 84505
Diffstat (limited to 'llvm/lib/Transforms/Utils/BasicBlockUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index 4931ab3..35907fd 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -425,14 +425,26 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB, if (L) { if (IsLoopEntry) { - if (Loop *PredLoop = LI->getLoopFor(Preds[0])) { - // Add the new block to the nearest enclosing loop (and not an - // adjacent loop). - while (PredLoop && !PredLoop->contains(BB)) - PredLoop = PredLoop->getParentLoop(); - if (PredLoop) - PredLoop->addBasicBlockToLoop(NewBB, LI->getBase()); - } + // Add the new block to the nearest enclosing loop (and not an + // adjacent loop). To find this, examine each of the predecessors and + // determine which loops enclose them, and select the most-nested loop + // which contains the loop containing the block being split. + Loop *InnermostPredLoop = 0; + for (unsigned i = 0; i != NumPreds; ++i) + if (Loop *PredLoop = LI->getLoopFor(Preds[i])) { + // Seek a loop which actually contains the block being split (to + // avoid adjacent loops). + while (PredLoop && !PredLoop->contains(BB)) + PredLoop = PredLoop->getParentLoop(); + // Select the most-nested of these loops which contains the block. + if (PredLoop && + PredLoop->contains(BB) && + (!InnermostPredLoop || + InnermostPredLoop->getLoopDepth() < PredLoop->getLoopDepth())) + InnermostPredLoop = PredLoop; + } + if (InnermostPredLoop) + InnermostPredLoop->addBasicBlockToLoop(NewBB, LI->getBase()); } else { L->addBasicBlockToLoop(NewBB, LI->getBase()); if (SplitMakesNewLoopHeader) |