[mlir][InferIntRangeCommon] Fix Division by Zero Crash (#151637)

Fixes #131273

Adds a check to avoid division when max value of denominator is zero.
This commit is contained in:
Veera 2025-08-17 10:56:34 -07:00 committed by GitHub
parent 71925a90c8
commit e1aa415220
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -290,8 +290,7 @@ static ConstantIntRanges inferDivURange(const ConstantIntRanges &lhs,
DivisionFixupFn fixup) {
const APInt &lhsMin = lhs.umin(), &lhsMax = lhs.umax(), &rhsMin = rhs.umin(),
&rhsMax = rhs.umax();
if (!rhsMin.isZero()) {
if (!rhsMin.isZero() && !rhsMax.isZero()) {
auto udiv = [&fixup](const APInt &a,
const APInt &b) -> std::optional<APInt> {
return fixup(a, b, a.udiv(b));

View File

@ -224,6 +224,15 @@ func.func @ceil_divui(%arg0 : index) -> i1 {
func.return %7 : i1
}
// CHECK-LABEL: func @ceil_divui_by_zero_issue_131273
// CHECK-NEXT: return
func.func @ceil_divui_by_zero_issue_131273() {
%0 = test.with_bounds {smax = 0 : i32, smin = -1 : i32, umax = 0 : i32, umin = -1 : i32} : i32
%c7_i32 = arith.constant 7 : i32
%1 = arith.ceildivui %c7_i32, %0 : i32
return
}
// CHECK-LABEL: func @ceil_divsi
// CHECK: %[[ret:.*]] = arith.cmpi eq
// CHECK: return %[[ret]]