[Mlir-commits] [mlir] [mlir] Compute ceildivs consistently for INT_MIN operands (PR #215696)
Hung Kuan Tseng
llvmlistbot at llvm.org
Wed Aug 12 07:47:28 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
----------------
Tim096 wrote:
Added as a second result in `@ceildivs_neg`: `ceildivs(-5, -2)` folds to `3`. That function already held the negative dividend case, so it seemed the natural home, and you are right that nothing else exercised the correction with two negative operands.
https://github.com/llvm/llvm-project/pull/215696
More information about the Mlir-commits
mailing list