[Mlir-commits] [mlir] e9b7a09 - [MLIR] Unconditionally take min of max lhs/rhs value in inferRemU (#110169)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Oct 3 20:17:47 PDT 2024
Author: goldsteinn
Date: 2024-10-03T22:17:44-05:00
New Revision: e9b7a093417bda7e0bed2bd62bcaeb7c2a662665
URL: https://github.com/llvm/llvm-project/commit/e9b7a093417bda7e0bed2bd62bcaeb7c2a662665
DIFF: https://github.com/llvm/llvm-project/commit/e9b7a093417bda7e0bed2bd62bcaeb7c2a662665.diff
LOG: [MLIR] Unconditionally take min of max lhs/rhs value in inferRemU (#110169)
- **[MLIR] Add test for inferring range of remu; NFC**
- **[MLIR] Unconditionally take min of max lhs/rhs value in inferRemU**
`arith.remu` cannot be larger than (rhs - 1) or lhs.
Added:
Modified:
mlir/lib/Interfaces/Utils/InferIntRangeCommon.cpp
mlir/test/Dialect/Arith/int-range-interface.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Interfaces/Utils/InferIntRangeCommon.cpp b/mlir/lib/Interfaces/Utils/InferIntRangeCommon.cpp
index ca3631d53bda99..ec9ed87723e1cc 100644
--- a/mlir/lib/Interfaces/Utils/InferIntRangeCommon.cpp
+++ b/mlir/lib/Interfaces/Utils/InferIntRangeCommon.cpp
@@ -444,10 +444,10 @@ mlir::intrange::inferRemU(ArrayRef<ConstantIntRanges> argRanges) {
unsigned width = rhsMin.getBitWidth();
APInt umin = APInt::getZero(width);
- APInt umax = APInt::getMaxValue(width);
+ // Remainder can't be larger than either of its arguments.
+ APInt umax = llvm::APIntOps::umin((rhsMax - 1), lhs.umax());
if (!rhsMin.isZero()) {
- umax = rhsMax - 1;
// Special case: sweeping out a contiguous range in N/[modulus]
if (rhsMin == rhsMax) {
const APInt &lhsMin = lhs.umin(), &lhsMax = lhs.umax();
diff --git a/mlir/test/Dialect/Arith/int-range-interface.mlir b/mlir/test/Dialect/Arith/int-range-interface.mlir
index 48fdb1cdced4dc..4b04229e5db52f 100644
--- a/mlir/test/Dialect/Arith/int-range-interface.mlir
+++ b/mlir/test/Dialect/Arith/int-range-interface.mlir
@@ -266,6 +266,19 @@ func.func @remui_base(%arg0 : index, %arg1 : index ) -> i1 {
func.return %3 : i1
}
+// CHECK-LABEL: func @remui_base_maybe_zero
+// CHECK: %[[true:.*]] = arith.constant true
+// CHECK: return %[[true]]
+func.func @remui_base_maybe_zero(%arg0 : index, %arg1 : index ) -> i1 {
+ %c4 = arith.constant 4 : index
+ %c5 = arith.constant 5 : index
+
+ %0 = arith.minui %arg1, %c4 : index
+ %1 = arith.remui %arg0, %0 : index
+ %2 = arith.cmpi ult, %1, %c5 : index
+ func.return %2 : i1
+}
+
// CHECK-LABEL: func @remsi_base
// CHECK: %[[ret:.*]] = arith.cmpi sge
// CHECK: return %[[ret]]
More information about the Mlir-commits
mailing list