if (!L->getLoopLatch())
return LoopDeletionResult::Unmodified;
- 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;
- }
+ auto *BTC = SE.getSymbolicMaxBackedgeTakenCount(L);
+ if (BTC->isZero()) {
+ // SCEV knows this backedge isn't taken!
+ breakLoopBackedge(L, DT, SE, LI, MSSA);
+ return LoopDeletionResult::Deleted;
}
- breakLoopBackedge(L, DT, SE, LI, MSSA);
- 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);
+ return LoopDeletionResult::Deleted;
+ }
+
+ return LoopDeletionResult::Unmodified;
}
/// Remove a loop if it is dead.