[Mlir-commits] [mlir] [MLIR] Unconditionally take min of max lhs/rhs value in inferRemU (PR #110169)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Oct 1 20:33:31 PDT 2024
https://github.com/goldsteinn updated https://github.com/llvm/llvm-project/pull/110169
>From 418c24d0614bdd30e955395be0866e6967e8f697 Mon Sep 17 00:00:00 2001
From: Noah Goldstein <goldstein.w.n at gmail.com>
Date: Thu, 26 Sep 2024 14:33:54 -0500
Subject: [PATCH 1/3] [MLIR] Add test for inferring range of remu; NFC
---
mlir/test/Dialect/Arith/int-range-interface.mlir | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/mlir/test/Dialect/Arith/int-range-interface.mlir b/mlir/test/Dialect/Arith/int-range-interface.mlir
index 48fdb1cdced4dc..ebe41b31f19f53 100644
--- a/mlir/test/Dialect/Arith/int-range-interface.mlir
+++ b/mlir/test/Dialect/Arith/int-range-interface.mlir
@@ -266,6 +266,18 @@ func.func @remui_base(%arg0 : index, %arg1 : index ) -> i1 {
func.return %3 : i1
}
+// CHECK-LABEL: func @remui_base_maybe_zero
+// CHECK: %[[ret:.*]] = arith.cmpi ult
+// CHECK: return %[[ret]]
+func.func @remui_base_maybe_zero(%arg0 : index, %arg1 : index ) -> i1 {
+ %c4 = arith.constant 4 : index
+
+ %0 = arith.minui %arg1, %c4 : index
+ %1 = arith.remui %arg0, %0 : index
+ %2 = arith.cmpi ult, %1, %c4 : index
+ func.return %2 : i1
+}
+
// CHECK-LABEL: func @remsi_base
// CHECK: %[[ret:.*]] = arith.cmpi sge
// CHECK: return %[[ret]]
>From f3e8f7cbecf599a79d3db66fd9a85a5c4cd7eca1 Mon Sep 17 00:00:00 2001
From: Noah Goldstein <goldstein.w.n at gmail.com>
Date: Tue, 1 Oct 2024 22:32:38 -0500
Subject: [PATCH 2/3] Update Tests
---
mlir/test/Dialect/Arith/int-range-interface.mlir | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mlir/test/Dialect/Arith/int-range-interface.mlir b/mlir/test/Dialect/Arith/int-range-interface.mlir
index ebe41b31f19f53..ca752da5171724 100644
--- a/mlir/test/Dialect/Arith/int-range-interface.mlir
+++ b/mlir/test/Dialect/Arith/int-range-interface.mlir
@@ -271,10 +271,11 @@ func.func @remui_base(%arg0 : index, %arg1 : index ) -> i1 {
// CHECK: return %[[ret]]
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, %c4 : index
+ %2 = arith.cmpi ult, %1, %c5 : index
func.return %2 : i1
}
>From 19055d65c83e00409d48943ead299d0a23c9dea0 Mon Sep 17 00:00:00 2001
From: Noah Goldstein <goldstein.w.n at gmail.com>
Date: Thu, 26 Sep 2024 15:27:57 -0500
Subject: [PATCH 3/3] [MLIR] Unconditionally take min of max lhs/rhs value in
inferRemU
`arith.remu` cannot be larger than (rhs - 1) or lhs.
---
mlir/lib/Interfaces/Utils/InferIntRangeCommon.cpp | 4 ++--
mlir/test/Dialect/Arith/int-range-interface.mlir | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
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 ca752da5171724..4b04229e5db52f 100644
--- a/mlir/test/Dialect/Arith/int-range-interface.mlir
+++ b/mlir/test/Dialect/Arith/int-range-interface.mlir
@@ -267,8 +267,8 @@ func.func @remui_base(%arg0 : index, %arg1 : index ) -> i1 {
}
// CHECK-LABEL: func @remui_base_maybe_zero
-// CHECK: %[[ret:.*]] = arith.cmpi ult
-// CHECK: return %[[ret]]
+// 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
More information about the Mlir-commits
mailing list