aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-10-19 16:04:50 +0000
committerDan Gohman <gohman@apple.com>2009-10-19 16:04:50 +0000
commitcd13d085ce8ca450d379abf127ced1cb097cce10 (patch)
tree5e545d4efd18acb564b73ca09f0563ca2816c3ce
parentd20dd8f42feee188300b2f59ea4a9c0ab4809690 (diff)
downloadexternal_llvm-cd13d085ce8ca450d379abf127ced1cb097cce10.zip
external_llvm-cd13d085ce8ca450d379abf127ced1cb097cce10.tar.gz
external_llvm-cd13d085ce8ca450d379abf127ced1cb097cce10.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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84505 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Utils/BasicBlockUtils.cpp28
-rw-r--r--test/Transforms/LoopSimplify/unreachable-loop-pred.ll20
2 files changed, 40 insertions, 8 deletions
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index 4931ab3..35907fd 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/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)
diff --git a/test/Transforms/LoopSimplify/unreachable-loop-pred.ll b/test/Transforms/LoopSimplify/unreachable-loop-pred.ll
new file mode 100644
index 0000000..faaaf97
--- /dev/null
+++ b/test/Transforms/LoopSimplify/unreachable-loop-pred.ll
@@ -0,0 +1,20 @@
+; RUN: opt -S -loopsimplify -disable-output -verify-loop-info -verify-dom-info < %s
+; PR5235
+
+; When loopsimplify inserts a preheader for this loop, it should add the new
+; block to the enclosing loop and not get confused by the unreachable
+; bogus loop entry.
+
+define void @is_extract_cab() nounwind {
+entry:
+ br label %header
+
+header: ; preds = %if.end206, %cond.end66, %if.end23
+ br label %while.body115
+
+while.body115: ; preds = %9, %if.end192, %if.end101
+ br i1 undef, label %header, label %while.body115
+
+foo:
+ br label %while.body115
+}