[Mlir-commits] [mlir] [mlir][arith] Widen index_cast of nsw truncations to the original value (PR #224460)

Slava Zakharin llvmlistbot at llvm.org
Fri Sep 18 10:53:35 PDT 2026


================
@@ -487,6 +487,27 @@ func.func @extSIOfExtSI(%arg0: i1) -> i64 {
   return %ext2 : i64
 }
 
+// CHECK-LABEL: @indexCastOfTruncINSW
+//       CHECK:   %[[index:.+]] = arith.index_cast %arg0 : i64 to index
+//       CHECK:   return %[[index]] : index
+func.func @indexCastOfTruncINSW(%arg0: i64) -> index {
+  %trunc = arith.trunci %arg0 overflow<nsw> : i64 to i32
+  %index = arith.index_cast %trunc : i32 to index
+  return %index : index
+}
+
+// CHECK-LABEL: @indexCastOfSubITruncINSW
+//       CHECK:   %[[offset:.+]] = arith.extsi %arg1 : i32 to i64
----------------
vzakhari wrote:

The profitability of this rewrite on its own is questionable. Can we limit it to the cases where the other operand of sub is a constant?

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


More information about the Mlir-commits mailing list