The "small range with constant divisor" optimization in `inferAffineExpr` for `AffineExprKind::Mod` assumed that if the dividend range span (`lhsMax - lhsMin`) is less than the divisor, then the mod results form a contiguous range. This is not always true, as the range can straddle a modulus boundary. For example, `[14, 17] mod 8`: - Span is 3 < 8, so the old condition passed - But `14%8=6` and `17%8=1` (wraps at 16) - `umin=6, umax=1` → assertion `umin.ule(umax)` fails The fix adds a same-quotient check (`lhsMin/rhs == lhsMax/rhs`) to ensure both endpoints fall within the same modular period. When they don't, we fall back to the conservative `[0, divisor-1]` range. Assisted-by: Cursor (Claude) Signed-off-by: Yu-Zhewen <zhewenyu@amd.com>
Multi-Level Intermediate Representation
See https://mlir.llvm.org/ for more information.