[Mlir-commits] [mlir] [mlir][IntRangeAnalysis] Add regression tests for affine division by zero (PR #205347)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Oct 28 20:04:27 PDT 2026
https://github.com/Chennesxu updated https://github.com/llvm/llvm-project/pull/205347
>From e3d361f540f44c85add0f00d59cb44d27a787049 Mon Sep 17 00:00:00 2001
From: Chennes <xuchen359 at gmail.com>
Date: Thu, 29 Oct 2026 09:45:42 +0800
Subject: [PATCH 1/2] [mlir][IntRangeAnalysis] Add regression tests for affine
division by zero
Cover affine floordiv and ceildiv with literal zero divisors. Check that
integer range inference returns the full range without crashing.
The crash reported in #205072 was fixed by #234159.
---
.../Dialect/Affine/int-range-interface.mlir | 23 +++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/mlir/test/Dialect/Affine/int-range-interface.mlir b/mlir/test/Dialect/Affine/int-range-interface.mlir
index 8dc12401ca142d..850493435c230b 100644
--- a/mlir/test/Dialect/Affine/int-range-interface.mlir
+++ b/mlir/test/Dialect/Affine/int-range-interface.mlir
@@ -171,3 +171,26 @@ func.func @affine_apply_mod_negative_dividend() -> index {
%1 = test.reflect_bounds %0 : index
func.return %1 : index
}
+
+// A literal zero divisor is degenerate (affine floordiv/ceildiv require a
+// strictly positive divisor). Range inference must not divide by zero; it
+// returns the full range instead of crashing.
+// CHECK-LABEL: func @affine_apply_floordiv_zero
+// CHECK: test.reflect_bounds {smax = 9223372036854775807 : index, smin = -9223372036854775808 : index, umax = -1 : index, umin = 0 : index}
+func.func @affine_apply_floordiv_zero() -> index {
+ %d0 = test.with_bounds { umin = 5 : index, umax = 10 : index,
+ smin = 5 : index, smax = 10 : index } : index
+ %0 = affine.apply affine_map<(d0) -> (d0 floordiv 0)>(%d0)
+ %1 = test.reflect_bounds %0 : index
+ func.return %1 : index
+}
+
+// CHECK-LABEL: func @affine_apply_ceildiv_zero
+// CHECK: test.reflect_bounds {smax = 9223372036854775807 : index, smin = -9223372036854775808 : index, umax = -1 : index, umin = 0 : index}
+func.func @affine_apply_ceildiv_zero() -> index {
+ %d0 = test.with_bounds { umin = 5 : index, umax = 10 : index,
+ smin = 5 : index, smax = 10 : index } : index
+ %0 = affine.apply affine_map<(d0) -> (d0 ceildiv 0)>(%d0)
+ %1 = test.reflect_bounds %0 : index
+ func.return %1 : index
+}
>From 208ae4860f5cb1b23a7c7cf53dafc27d73acccb4 Mon Sep 17 00:00:00 2001
From: Chennes <xuchen359 at gmail.com>
Date: Thu, 29 Oct 2026 11:03:58 +0800
Subject: [PATCH 2/2] [mlir][test] Fix property syntax in affine integer range
tests
Update the zero-divisor tests to use property dictionaries and match
the current printing order in FileCheck expectations.
---
mlir/test/Dialect/Affine/int-range-interface.mlir | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/mlir/test/Dialect/Affine/int-range-interface.mlir b/mlir/test/Dialect/Affine/int-range-interface.mlir
index 850493435c230b..2b253d45f6d5b9 100644
--- a/mlir/test/Dialect/Affine/int-range-interface.mlir
+++ b/mlir/test/Dialect/Affine/int-range-interface.mlir
@@ -176,20 +176,20 @@ func.func @affine_apply_mod_negative_dividend() -> index {
// strictly positive divisor). Range inference must not divide by zero; it
// returns the full range instead of crashing.
// CHECK-LABEL: func @affine_apply_floordiv_zero
-// CHECK: test.reflect_bounds {smax = 9223372036854775807 : index, smin = -9223372036854775808 : index, umax = -1 : index, umin = 0 : index}
+// CHECK: test.reflect_bounds <umin = 0 : index, umax = -1 : index, smin = -9223372036854775808 : index, smax = 9223372036854775807 : index>
func.func @affine_apply_floordiv_zero() -> index {
- %d0 = test.with_bounds { umin = 5 : index, umax = 10 : index,
- smin = 5 : index, smax = 10 : index } : index
+ %d0 = test.with_bounds < umin = 5 : index, umax = 10 : index,
+ smin = 5 : index, smax = 10 : index > : index
%0 = affine.apply affine_map<(d0) -> (d0 floordiv 0)>(%d0)
%1 = test.reflect_bounds %0 : index
func.return %1 : index
}
// CHECK-LABEL: func @affine_apply_ceildiv_zero
-// CHECK: test.reflect_bounds {smax = 9223372036854775807 : index, smin = -9223372036854775808 : index, umax = -1 : index, umin = 0 : index}
+// CHECK: test.reflect_bounds <umin = 0 : index, umax = -1 : index, smin = -9223372036854775808 : index, smax = 9223372036854775807 : index>
func.func @affine_apply_ceildiv_zero() -> index {
- %d0 = test.with_bounds { umin = 5 : index, umax = 10 : index,
- smin = 5 : index, smax = 10 : index } : index
+ %d0 = test.with_bounds < umin = 5 : index, umax = 10 : index,
+ smin = 5 : index, smax = 10 : index > : index
%0 = affine.apply affine_map<(d0) -> (d0 ceildiv 0)>(%d0)
%1 = test.reflect_bounds %0 : index
func.return %1 : index
More information about the Mlir-commits
mailing list