Skip to content

Commit e1aa415

Browse files
[mlir][InferIntRangeCommon] Fix Division by Zero Crash (#151637)
Fixes #131273 Adds a check to avoid division when max value of denominator is zero.
1 parent 71925a9 commit e1aa415

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

mlir/lib/Interfaces/Utils/InferIntRangeCommon.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,7 @@ static ConstantIntRanges inferDivURange(const ConstantIntRanges &lhs,
290290
DivisionFixupFn fixup) {
291291
const APInt &lhsMin = lhs.umin(), &lhsMax = lhs.umax(), &rhsMin = rhs.umin(),
292292
&rhsMax = rhs.umax();
293-
294-
if (!rhsMin.isZero()) {
293+
if (!rhsMin.isZero() && !rhsMax.isZero()) {
295294
auto udiv = [&fixup](const APInt &a,
296295
const APInt &b) -> std::optional<APInt> {
297296
return fixup(a, b, a.udiv(b));

mlir/test/Dialect/Arith/int-range-interface.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,15 @@ func.func @ceil_divui(%arg0 : index) -> i1 {
224224
func.return %7 : i1
225225
}
226226

227+
// CHECK-LABEL: func @ceil_divui_by_zero_issue_131273
228+
// CHECK-NEXT: return
229+
func.func @ceil_divui_by_zero_issue_131273() {
230+
%0 = test.with_bounds {smax = 0 : i32, smin = -1 : i32, umax = 0 : i32, umin = -1 : i32} : i32
231+
%c7_i32 = arith.constant 7 : i32
232+
%1 = arith.ceildivui %c7_i32, %0 : i32
233+
return
234+
}
235+
227236
// CHECK-LABEL: func @ceil_divsi
228237
// CHECK: %[[ret:.*]] = arith.cmpi eq
229238
// CHECK: return %[[ret]]

0 commit comments

Comments
 (0)