aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopDeletion.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopDeletion.cpp30
1 files changed, 12 insertions, 18 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
index 5814e2f043d5..361d6c0d9381 100644
--- a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
@@ -407,25 +407,19 @@ breakBackedgeIfNotTaken(Loop *L, DominatorTree &DT, ScalarEvolution &SE,
if (!L->getLoopLatch())
return LoopDeletionResult::Unmodified;
- auto *BTC = SE.getSymbolicMaxBackedgeTakenCount(L);
- if (BTC->isZero()) {
- // SCEV knows this backedge isn't taken!
- breakLoopBackedge(L, DT, SE, LI, MSSA);
- ++NumBackedgesBroken;
- return LoopDeletionResult::Deleted;
- }
-
- // If SCEV leaves open the possibility of a zero trip count, see if
- // symbolically evaluating the first iteration lets us prove the backedge
- // unreachable.
- if (isa<SCEVCouldNotCompute>(BTC) || !SE.isKnownNonZero(BTC))
- if (canProveExitOnFirstIteration(L, DT, LI)) {
- breakLoopBackedge(L, DT, SE, LI, MSSA);
- ++NumBackedgesBroken;
- return LoopDeletionResult::Deleted;
+ auto *BTCMax = SE.getConstantMaxBackedgeTakenCount(L);
+ if (!BTCMax->isZero()) {
+ auto *BTC = SE.getBackedgeTakenCount(L);
+ if (!BTC->isZero()) {
+ if (!isa<SCEVCouldNotCompute>(BTC) && SE.isKnownNonZero(BTC))
+ return LoopDeletionResult::Unmodified;
+ if (!canProveExitOnFirstIteration(L, DT, LI))
+ return LoopDeletionResult::Unmodified;
}
-
- return LoopDeletionResult::Unmodified;
+ }
+ ++NumBackedgesBroken;
+ breakLoopBackedge(L, DT, SE, LI, MSSA);
+ return LoopDeletionResult::Deleted;
}
/// Remove a loop if it is dead.