[Mlir-commits] [mlir] [MLIR] Unconditionally take min of max lhs/rhs value in inferRemU (PR #110169)

Krzysztof Drewniak llvmlistbot at llvm.org
Tue Oct 1 21:06:15 PDT 2024


================
@@ -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: %[[true:.*]] = arith.constant true
+// CHECK: return %[[true]]
+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
+}    
----------------
krzysz00 wrote:

This is a niche and expensive enough pattern match that I wouldn't make it a canonicalization - especially since we're using `minui` to stand in for any number of things that would impose a maximum on a value.

The following example, which wouldn't make sense as a canonicalization, should also fold
```mlir
func.func @f(%arg0 : index) -> i1 {
  %tid = gpu.thread_id x upper_bound 64 : index
  %clamped = arith.remui %arg0, %tid : index
  %c64 = arith.constant 64 : index
  %ret = arith.cmpi ult %clamped, %c64
  func.return %ret : i1
}
```
which should simplify to true

https://github.com/llvm/llvm-project/pull/110169


More information about the Mlir-commits mailing list