[Mlir-commits] [mlir] [mlir][arith] Add ValueBoundsOpInterface external models for the arith operations DivUI and DivSI (PR #206514)
Max Graey
llvmlistbot at llvm.org
Mon Jun 29 09:50:07 PDT 2026
================
@@ -136,6 +136,65 @@ func.func @arith_ceildivsi_non_pure(%a: index, %b: index) -> index {
// -----
+// CHECK-LABEL: func @arith_divui_constant()
+// CHECK: %[[c1:.*]] = arith.constant 1 : index
+// CHECK: return %[[c1]]
+func.func @arith_divui_constant() -> index {
+ %c7 = arith.constant 7 : index
+ %c5 = arith.constant 5 : index
+ %0 = arith.divui %c7, %c5 : index
+ %1 = "test.reify_bound"(%0) : (index) -> (index)
+ return %1 : index
+}
+
+// -----
+
+
+// CHECK-LABEL: func @arith_divui_positive_lhs()
+// CHECK: %[[c1:.*]] = arith.constant 1 : index
+// CHECK: return %[[c1]]
+
+func.func @arith_divui_positive_lhs() -> index {
+ %c7 = arith.constant 7 : index
+ %c5 = arith.constant 5 : index
+ %c1 = arith.constant 1 : index
+ %lhs = arith.maxsi %c7, %c1 : index
+ %0 = arith.divui %lhs, %c5 : index
+ %1 = "test.reify_bound"(%0) {type = "LB", constant} : (index) -> (index)
+ return %1 : index
+}
+
+
+// -----
+
+// CHECK-LABEL: func @arith_divsi_negative_positive()
+// CHECK: %[[cm1:.*]] = arith.constant -1 : index
+// CHECK: return %[[cm1]]
+func.func @arith_divsi_negative_positive() -> index {
+ %cm7 = arith.constant -7 : index
+ %c5 = arith.constant 5 : index
+ %0 = arith.divsi %cm7, %c5 : index
+ %1 = "test.reify_bound"(%0) : (index) -> (index)
+ return %1 : index
+}
+
+// -----
+
+// CHECK-LABEL: func @arith_divsi_negative_lhs()
+// CHECK: %[[cm2:.*]] = arith.constant -2 : index
+// CHECK: return %[[cm2]]
+func.func @arith_divsi_negative_lhs() -> index {
+ %c2 = arith.constant 2 : index
+ %cm7 = arith.constant -7 : index
+ %cm5 = arith.constant -5 : index
+ %lhs = arith.minsi %cm5, %cm7 : index
+ %0 = arith.divsi %lhs, %c2 : index
+ %1 = "test.reify_bound"(%0) {type = "UB", constant}: (index) -> (index)
+ return %1 : index
+}
----------------
MaxGraey wrote:
How this will behave with `signed_min / -1`?
```mlir
%smin = arith.constant -9223372036854775808
%neg_one = arith.constant -1
arith.divsi %smin, %neg_one
```
https://github.com/llvm/llvm-project/pull/206514
More information about the Mlir-commits
mailing list