[Mlir-commits] [mlir] [mlir][arith] Fold addi(x, not(x)) -> -1 (PR #212272)

Max Graey llvmlistbot at llvm.org
Tue Jul 28 01:21:17 PDT 2026


MaxGraey wrote:

How about generalize these and use `^ -1` hoisting:
```ocaml
addi(not(x), y) -> not(subi(x, y))
addi(x, not(y)) -> not(subi(y, x))
subi(not(x), y) -> not(addi(x, y))
```
and for special case when `x == y` next iteration will fold it to `-1`:
```ocaml
not(subi(x, x)) -> not(0) -> -1
not(subi(x, x)) -> not(0) -> -1
```
Using hoisting unlocks more optimization DRRs like:
```ocaml
addi(subi(not(x), c0), c1) -> 
  addi(not(addi(x, c0)), c1) ->
    not(subi(addi(x, c0), c1)) -> not(addi(x, c0 - c1))
```

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


More information about the Mlir-commits mailing list