llvm-project
5d51ec23 - [mlir][Affine] Avoid overflow when lowering ceildiv (#246923)

Commit
1 day ago
[mlir][Affine] Avoid overflow when lowering ceildiv (#246923) AffineApplyExpander::visitCeilDivExpr negated a non-positive dividend with `0 - lhs` before dividing. For the minimum signed value, that subtraction wraps and the final negation flips the sign of the result, e.g. INT64_MIN ceildiv 5 was lowered to +1844674407370955161 instead of -1844674407370955161. For a non-positive dividend and a positive divisor, truncating division already rounds towards positive infinity, so the dividend can be used directly. This removes both negations, fixes the overflow, and shortens the generated IR by two operations. Fixes #246593. Assisted-by: DeepSeek-V4.1-Flash-1017
Author
Parents
Loading