[llvm] [SCEV] Consider IVMayOverflow to use cheap BE-count formula. (PR #218694)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 28 09:20:39 PDT 2026
================
@@ -13564,9 +13566,20 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
// So dividing that by Stride gives zero.
//
// * For RHS > Start (End is RHS), the backedge count must be
- // "RHS-Start /uceil Stride". Together with the precondition
- // "Start - Stride < Start", we have "RHS > Start > Start - Stride".
- // As such RHS - (Start - Stride) - 1 does not overflow.
+ // "RHS-Start /uceil Stride", so it is sufficient to show that the
+ // numerator "((RHS - 1) - (Start - Stride))" does not overflow.
+ //
+ // If "Start - Stride < Start" holds, we have
+ // "RHS > Start > Start - Stride". As such
+ // "RHS - (Start - Stride) - 1" does not overflow, which is the
+ // reassociated numerator.
+ //
+ // Otherwise !IVMayOverflow guarantees "RHS + (Stride - 1) <= MaxV ",
----------------
nikic wrote:
```suggestion
// Otherwise !IVMayOverflow guarantees "RHS + (Stride - 1) <= MaxV",
```
https://github.com/llvm/llvm-project/pull/218694
More information about the llvm-commits
mailing list