[Mlir-commits] [mlir] [mlir][arith] Fix overflow bug in arith::CeilDivSIOp::fold (PR #90947)

Kai Sasaki llvmlistbot at llvm.org
Fri May 3 15:42:17 PDT 2024


================
@@ -478,6 +478,32 @@ func.func @simple_arith.ceildivsi() -> (i32, i32, i32, i32, i32) {
 
 // -----
 
+// CHECK-LABEL: func @simple_arith.ceildivsi_overflow
+func.func @simple_arith.ceildivsi_overflow() -> (i8, i16, i32) {
+  // The negative values below are MININTs for the corresponding bit-width. The
+  // folder will try to negate them (so that the division operartes on two
+  // positive numbers), but that would cause overflow (negating MININT
+  // overflows). Hence folding should not happen and the original ceildivsi is
+  // preserved.
+
+  // CHECK-COUNT-3:  arith.ceildivsi
----------------
Lewuathe wrote:

It's nit. It might have been better to check whether the original one is preserved instead of just checking the count.

something like

```suggestion
  // CHECK-NEXT: %[[C1:.*]] = arith.constant 7 : i8
  // CHECK-NEXT: %[[MIN1:.*]] = arith.constant -128 : i8
  // CHECK-NEXT: %[[CEILDIV1:.*]] = arith.ceildivsi %[[MIN1]], %[[C1]]  : i32
```

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


More information about the Mlir-commits mailing list