[Mlir-commits] [mlir] [mlir][arith] Add `exact` to `index_cast{, ui}` (PR #183395)

Krzysztof Drewniak llvmlistbot at llvm.org
Wed Feb 25 13:55:30 PST 2026


================
@@ -290,28 +290,30 @@ def SelectI1ToNot :
 
 // index_cast(index_cast(x)) -> x, if dstType == srcType.
 def IndexCastOfIndexCast :
-    Pat<(Arith_IndexCastOp:$res (Arith_IndexCastOp $x)),
+    Pat<(Arith_IndexCastOp:$res (Arith_IndexCastOp $x, $exact1), $exact2),
         (replaceWithValue $x),
         [(Constraint<CPred<"$0.getType() == $1.getType()">> $res, $x)]>;
 
 // index_cast(extsi(x)) -> index_cast(x)
 def IndexCastOfExtSI :
-    Pat<(Arith_IndexCastOp (Arith_ExtSIOp $x)), (Arith_IndexCastOp $x)>;
+    Pat<(Arith_IndexCastOp (Arith_ExtSIOp $x), $exact),
+        (Arith_IndexCastOp $x, $exact)>;
 
 //===----------------------------------------------------------------------===//
 // IndexCastUIOp
 //===----------------------------------------------------------------------===//
 
 // index_castui(index_castui(x)) -> x, if dstType == srcType.
 def IndexCastUIOfIndexCastUI :
-    Pat<(Arith_IndexCastUIOp:$res (Arith_IndexCastUIOp $x)),
+    Pat<(Arith_IndexCastUIOp:$res
+          (Arith_IndexCastUIOp $x, $nneg1, $exact1), $nneg2, $exact2),
----------------
krzysz00 wrote:

So it's possible that the assumptions in `exact` have secretly been hiding in the canonicalization patterns this whole time.

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


More information about the Mlir-commits mailing list