[Mlir-commits] [mlir] [mlir][arith] Move canonicalization patterns to fold (PR #184381)
Razvan Lupusoru
llvmlistbot at llvm.org
Tue Mar 3 12:54:04 PST 2026
================
@@ -1845,6 +1845,14 @@ bool arith::IndexCastOp::areCastCompatible(TypeRange inputs,
}
OpFoldResult arith::IndexCastOp::fold(FoldAdaptor adaptor) {
+ // index_cast(index_cast(x, exact)) -> x, when result type matches x's type.
+ // The inner exact guarantees the iN -> index conversion is lossless,
+ // so the roundtrip through index preserves the value.
+ if (auto innerCast = getIn().getDefiningOp<IndexCastOp>()) {
+ if (innerCast.getIn().getType() == getType() && innerCast.getIsExact())
----------------
razvanlupusoru wrote:
I posted a question about this scenario in your previous PR:
https://github.com/llvm/llvm-project/pull/183395/changes#r2880422529
I hope we reach a reasonable resolution :) Thank you!
https://github.com/llvm/llvm-project/pull/184381
More information about the Mlir-commits
mailing list