Index: llvm/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -11947,6 +11947,10 @@ } else { MaxBECount = computeMaxBECountForLT( Start, Stride, RHS, getTypeSizeInBits(LHS->getType()), IsSigned); + // If we prove the max count is zero, so is the symbolic bound. This can + // happen due to differences in how we reason about bounds impied by UB. + if (MaxBECount->isZero()) + BECount = MaxBECount; } if (isa(MaxBECount) && Index: llvm/test/Analysis/ScalarEvolution/max-trip-count.ll =================================================================== --- llvm/test/Analysis/ScalarEvolution/max-trip-count.ll +++ llvm/test/Analysis/ScalarEvolution/max-trip-count.ll @@ -458,7 +458,7 @@ define void @max_overflow(i8 %n) mustprogress { ; CHECK-LABEL: Determining loop execution counts for: @max_overflow -; CHECK: Loop %loop: backedge-taken count is (-126 + (126 smax %n)) +; CHECK: Loop %loop: backedge-taken count is 0 ; CHECK: Loop %loop: max backedge-taken count is 0 entry: br label %loop