[Mlir-commits] [mlir] [mlir][Transforms] Greedy pattern rewriter: fix infinite folding loop (PR #161145)

Matthias Springer llvmlistbot at llvm.org
Tue Sep 30 03:47:01 PDT 2025


matthias-springer wrote:

Ok, then it cannot be fixed in the verifier.

Then we have to fix the folder. The API of the single-result folder is: if the folder returns the op result, the op was folded in-place. This is violated here. (I updated the PR. But only in one place. There are many places like that.)

Also, it doesn't fix the issue yet, because now this canonicalization pattern gets into an infinite loop. Unfortunately, it's written in TableGen and there may be no way to fix this without rewriting it in C++:
```
// addi(addi(x, c0), c1) -> addi(x, c0 + c1)
def AddIAddConstant :
    Pat<(Arith_AddIOp:$res
          (Arith_AddIOp $x, (ConstantLikeMatcher APIntAttr:$c0), $ovf1),
          (ConstantLikeMatcher APIntAttr:$c1), $ovf2),
        (Arith_AddIOp $x, (Arith_ConstantOp (AddIntAttrs $res, $c0, $c1)),
            (MergeOverflow $ovf1, $ovf2))>;
```



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


More information about the Mlir-commits mailing list