[Mlir-commits] [mlir] [mlir] Compute ceildivs consistently for INT_MIN operands (PR #215696)

Jakub Kuderski llvmlistbot at llvm.org
Wed Aug 12 06:35:36 PDT 2026


================
@@ -161,21 +161,38 @@ func.func @ceildivs_neg() -> index {
 
 // CHECK-LABEL: @ceildivs_edge
 func.func @ceildivs_edge() -> (index, index) {
+  // CHECK-DAG: %[[B:.*]] = index.constant -2147483647
+  // CHECK-DAG: %[[NEG_ONE:.*]] = index.constant -1
+  // CHECK-DAG: %[[INT_MIN:.*]] = index.constant -2147483648
   %cn1 = index.constant -1
   %cIntMin = index.constant -2147483648
   %cIntMax = index.constant 2147483647
 
-  // The result is 0 on 32-bit.
-  // CHECK-DAG: %[[A:.*]] = index.constant 2147483648
+  // The result, 2147483648, is not representable on 32-bit, so this does not
+  // fold on either bitwidth.
+  // CHECK: %[[A:.*]] = index.ceildivs %[[INT_MIN]], %[[NEG_ONE]]
   %0 = index.ceildivs %cIntMin, %cn1
 
-  // CHECK-DAG: %[[B:.*]] = index.constant -2147483647
   %1 = index.ceildivs %cIntMax, %cn1
 
   // CHECK: return %[[A]], %[[B]]
   return %0, %1 : index, index
 }
 
+// CHECK-LABEL: @ceildivs_intmin_dividend
+func.func @ceildivs_intmin_dividend() -> index {
+  %c7 = index.constant 7
+  %cIntMin = index.constant -2147483648
+
+  // Negating the dividend wrapped on 32-bit and gave a positive result there,
+  // which disagreed with the 64-bit one, so this used not to fold at all.
+  // CHECK: %[[A:.*]] = index.constant -306783378
+  %0 = index.ceildivs %cIntMin, %c7
----------------
kuhar wrote:

It would be useful to add a negative/negative inexact fold case, such as `ceildivs(-5, -2) == 3`. The rewritten correction handles same-sign operands, but the current tests exercise that path only with two positive operands; the negative-divisor cases are exact or overflow.

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


More information about the Mlir-commits mailing list