Index: lib/Analysis/ScalarEvolution.cpp =================================================================== --- lib/Analysis/ScalarEvolution.cpp +++ lib/Analysis/ScalarEvolution.cpp @@ -6387,7 +6387,17 @@ unsigned ScalarEvolution::getSmallConstantMaxTripCount(const Loop *L) { const auto *MaxExitCount = dyn_cast(getMaxBackedgeTakenCount(L)); - return getConstantTripCount(MaxExitCount); + if (unsigned C = getConstantTripCount(MaxExitCount)) + return C; + + SCEVUnionPredicate Ps; + const SCEV *PredBEC = getPredicatedBackedgeTakenCount(L, Ps); + if (PredBEC != getCouldNotCompute()) { + APInt S = getUnsignedRange(PredBEC).getSetSize(); + if (S.getActiveBits() < 32) + return S.getZExtValue(); + } + return 0; } unsigned ScalarEvolution::getSmallConstantTripMultiple(const Loop *L) {