[Mlir-commits] [mlir] [mlir][Index] Fix INT_MIN overflow in CeilDivSOp constant folding (PR #223127)
Cheng-Chieh Liu
llvmlistbot at llvm.org
Sat Sep 12 01:12:21 PDT 2026
jay87406 wrote:
Thanks for the review.
Currently, `index.ceildivs` (along with `index.divs` and `index.floordivs`) explicitly documents this behavior in `IndexOps.td`:
> "Note: division by zero and signed division overflow are undefined behaviour."
So `INT_MIN / -1` is already considered UB under the current spec. I kept the folder consistent with this existing convention (and how `arith::CeilDivSIOp::fold` handles it) by declining to fold it.
The main fix here is actually for cases like `ceildivs(INT_MIN, 2)`. This is a valid, representable value that was incorrectly folding to `4611686018427387904` due to an unhandled overflow during the internal APInt calculation.
If we want to redefine `index` as a genuinely unbounded type where signed overflow doesn't exist, that feels like a larger semantic change that would affect all other div/rem folders and docs in this file. I'd prefer to address that separately and keep this PR focused on fixing the incorrect folding bug.
https://github.com/llvm/llvm-project/pull/223127
More information about the Mlir-commits
mailing list