[Mlir-commits] [mlir] [MLIR][DRR] Fix inconsistent operand and arg index usage (PR #139816)

Xiaomin Liu llvmlistbot at llvm.org
Sat May 17 07:15:01 PDT 2025


================
@@ -1883,6 +1888,9 @@ def : Pat<(TestEitherOpA (either (TestEitherOpB I32:$arg1, $_),
                           $x),
           (TestEitherOpB $arg2, $x)>;
 
+def : Pat<(TestEitherOpC ConstantAttr<I32Attr, "0">, (either $arg1, I32:$arg2)),
+          (TestEitherOpB $arg1, $arg2)>;
+
----------------
xl4624 wrote:

Without the changes this test fails on a cast assertion:

```
mlir-tblgen: /home/xiaomin/dev/llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From &) [To = mlir::tblgen::NamedTypeConstraint *, From = llvm::PointerUnion<mlir::tblgen::NamedAttribute *, mlir::tblgen::NamedProperty *, mlir::tblgen::NamedTypeConstraint *>]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
```

Coming from:

https://github.com/llvm/llvm-project/blob/bf1d4a0710a6e1d2c99e579bcf435b92ab5d0506/mlir/tools/mlir-tblgen/RewriterGen.cpp#L677-L683

In the test case above, `operandIndex` and `argIndex` get out of sync due to the Attribute being in the front and then we cast with the wrong index (specifically when `argIndex=1` and `operandIndex=0`)

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


More information about the Mlir-commits mailing list