[Mlir-commits] [mlir] [MLIR][Arith] Fix unsound addi/subi constant-fold when merged overflow flags would be violated (PR #189164)

Mathieu Fehr llvmlistbot at llvm.org
Wed Apr 8 11:10:33 PDT 2026


math-fehr wrote:

Sorry for the delay, got sick last week!
I tried to brainstorm again on it with [my tool](https://github.com/opencompl/xdsl-smt/commit/168084d49ad2949e4ed206c404f8ee31b259c6ec), and my conclusion for `(x + cst1) + cst2` is:
* If the merged overflow flags are `none`, `nuw`, or `nsw, nuw`, then the rewrite is always safe even if there is an overflow using the merged flags when adding constants.
* If the merged overflow flags are `nsw` only, then I think that checking if `cst1 + cst2` overflow should be the right condition to apply the rewrite or not. I don't have a "proof" that this isn't too restrictive yet though, but at least it's correct.

I haven't done this for the other operations, but I believe for anything `add/sub` related it should look the same!

https://github.com/llvm/llvm-project/pull/189164


More information about the Mlir-commits mailing list