aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopInterchange.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopInterchange.cpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index 3cf3517..05b807b 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -831,18 +831,26 @@ bool LoopInterchangeLegality::currentLimitations() {
}
Inductions.clear();
- if (!findInductionAndReductions(InnerLoop, Inductions, nullptr)) {
- LLVM_DEBUG(
- dbgs() << "Only inner loops with induction or reduction PHI nodes "
- << "are supported currently.\n");
- ORE->emit([&]() {
- return OptimizationRemarkMissed(DEBUG_TYPE, "UnsupportedPHIInner",
- InnerLoop->getStartLoc(),
- InnerLoop->getHeader())
- << "Only inner loops with induction or reduction PHI nodes can be"
- " interchange currently.";
- });
- return true;
+ // For multi-level loop nests, make sure that all phi nodes for inner loops
+ // at all levels can be recognized as a induction or reduction phi. Bail out
+ // if a phi node at a certain nesting level cannot be properly recognized.
+ Loop *CurLevelLoop = OuterLoop;
+ while (!CurLevelLoop->getSubLoops().empty()) {
+ // We already made sure that the loop nest is tightly nested.
+ CurLevelLoop = CurLevelLoop->getSubLoops().front();
+ if (!findInductionAndReductions(CurLevelLoop, Inductions, nullptr)) {
+ LLVM_DEBUG(
+ dbgs() << "Only inner loops with induction or reduction PHI nodes "
+ << "are supported currently.\n");
+ ORE->emit([&]() {
+ return OptimizationRemarkMissed(DEBUG_TYPE, "UnsupportedPHIInner",
+ CurLevelLoop->getStartLoc(),
+ CurLevelLoop->getHeader())
+ << "Only inner loops with induction or reduction PHI nodes can be"
+ " interchange currently.";
+ });
+ return true;
+ }
}
// TODO: Triangular loops are not handled for now.