Skip to content

Commit 2a80c33

Browse files
committed
[MLIR] Unconditionally take min of max lhs/rhs value in inferRemU
`arith.remu` cannot be larger than (rhs - 1) or lhs.
1 parent 525a55d commit 2a80c33

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

mlir/lib/Interfaces/Utils/InferIntRangeCommon.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,10 @@ mlir::intrange::inferRemU(ArrayRef<ConstantIntRanges> argRanges) {
444444

445445
unsigned width = rhsMin.getBitWidth();
446446
APInt umin = APInt::getZero(width);
447-
APInt umax = APInt::getMaxValue(width);
447+
// Remainder can't be larger than either of its arguments.
448+
APInt umax = llvm::APIntOps::umin((rhsMax - 1), lhs.umax());
448449

449450
if (!rhsMin.isZero()) {
450-
umax = rhsMax - 1;
451451
// Special case: sweeping out a contiguous range in N/[modulus]
452452
if (rhsMin == rhsMax) {
453453
const APInt &lhsMin = lhs.umin(), &lhsMax = lhs.umax();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ func.func @remui_base(%arg0 : index, %arg1 : index ) -> i1 {
267267
}
268268

269269
// CHECK-LABEL: func @remui_base_maybe_zero
270-
// CHECK: %[[ret:.*]] = arith.cmpi ult
271-
// CHECK: return %[[ret]]
270+
// CHECK: %[[true:.*]] = arith.constant true
271+
// CHECK: return %[[true]]
272272
func.func @remui_base_maybe_zero(%arg0 : index, %arg1 : index ) -> i1 {
273273
%c4 = arith.constant 4 : index
274274

0 commit comments

Comments
 (0)