[Mlir-commits] [mlir] [mlir][arith] Add constraints to the MulIOp for preventing type mismatch while folding (PR #136093)
Prakhar Dixit
llvmlistbot at llvm.org
Thu Apr 17 01:44:40 PDT 2025
================
@@ -1234,6 +1234,24 @@ func.func @doubleAddSub2(%arg0: index, %arg1 : index) -> index {
return %add : index
}
+// Negative test case to ensure no further folding is performed when there's a type mismatch between the values and the result.
+// CHECK-LABEL: func.func @nested_muli() -> i32 {
+// CHECK: %[[VAL_0:.*]] = "test.constant"() <{value = 2147483647 : i64}> : () -> i32
+// CHECK: %[[VAL_1:.*]] = "test.constant"() <{value = -2147483648 : i64}> : () -> i32
+// CHECK: %[[VAL_2:.*]] = "test.constant"() <{value = 2147483648 : i64}> : () -> i32
+// CHECK: %[[VAL_3:.*]] = arith.muli %[[VAL_0]], %[[VAL_1]] : i32
+// CHECK: %[[VAL_4:.*]] = arith.muli %[[VAL_3]], %[[VAL_2]] : i32
+// CHECK: return %[[VAL_4]] : i32
+// CHECK: }
+func.func @nested_muli() -> (i32) {
+ %0 = "test.constant"() {value = 0x7fffffff} : () -> i32
+ %1 = "test.constant"() {value = -2147483648} : () -> i32
+ %2 = "test.constant"() {value = 0x80000000} : () -> i32
+ %4 = arith.muli %0, %1 : i32
+ %5 = arith.muli %4, %2 : i32
+ return %5 : i32
----------------
Prakhar-Dixit wrote:
Thanks for reviewing!
I'm also not sure why it was allowed in the first place, and this seems to be the ideal fix.
https://github.com/llvm/llvm-project/pull/136093
More information about the Mlir-commits
mailing list