[Mlir-commits] [mlir] 051612c - [mlir][ValueBounds] memref.dim and tensor.dim are always positive (#122804)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Jan 13 15:48:07 PST 2025
Author: Krzysztof Drewniak
Date: 2025-01-13T17:48:03-06:00
New Revision: 051612c0180e4e5a9ba750a994a91d2c1b05b00c
URL: https://github.com/llvm/llvm-project/commit/051612c0180e4e5a9ba750a994a91d2c1b05b00c
DIFF: https://github.com/llvm/llvm-project/commit/051612c0180e4e5a9ba750a994a91d2c1b05b00c.diff
LOG: [mlir][ValueBounds] memref.dim and tensor.dim are always positive (#122804)
Add the constraint that the length of a memref or tensor dimension is
always non-negative (at least 0) even if we don't know which dimension
we're querying the length of.
Added:
Modified:
mlir/lib/Dialect/MemRef/IR/ValueBoundsOpInterfaceImpl.cpp
mlir/lib/Dialect/Tensor/IR/ValueBoundsOpInterfaceImpl.cpp
mlir/test/Dialect/MemRef/value-bounds-op-interface-impl.mlir
mlir/test/Dialect/Tensor/value-bounds-op-interface-impl.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/MemRef/IR/ValueBoundsOpInterfaceImpl.cpp b/mlir/lib/Dialect/MemRef/IR/ValueBoundsOpInterfaceImpl.cpp
index daec22cf6ebdcd..11400de35e4300 100644
--- a/mlir/lib/Dialect/MemRef/IR/ValueBoundsOpInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/MemRef/IR/ValueBoundsOpInterfaceImpl.cpp
@@ -51,6 +51,7 @@ struct DimOpInterface
auto dimOp = cast<DimOp>(op);
assert(value == dimOp.getResult() && "invalid value");
+ cstr.bound(value) >= 0;
auto constIndex = dimOp.getConstantIndex();
if (!constIndex.has_value())
return;
diff --git a/mlir/lib/Dialect/Tensor/IR/ValueBoundsOpInterfaceImpl.cpp b/mlir/lib/Dialect/Tensor/IR/ValueBoundsOpInterfaceImpl.cpp
index 06f2c16406d3c0..5bb6259dd543d0 100644
--- a/mlir/lib/Dialect/Tensor/IR/ValueBoundsOpInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/ValueBoundsOpInterfaceImpl.cpp
@@ -38,6 +38,7 @@ struct DimOpInterface
auto dimOp = cast<DimOp>(op);
assert(value == dimOp.getResult() && "invalid value");
+ cstr.bound(value) >= 0;
auto constIndex = dimOp.getConstantIndex();
if (!constIndex.has_value())
return;
diff --git a/mlir/test/Dialect/MemRef/value-bounds-op-interface-impl.mlir b/mlir/test/Dialect/MemRef/value-bounds-op-interface-impl.mlir
index dc311c6b59ea47..8bd7ae8df90490 100644
--- a/mlir/test/Dialect/MemRef/value-bounds-op-interface-impl.mlir
+++ b/mlir/test/Dialect/MemRef/value-bounds-op-interface-impl.mlir
@@ -52,6 +52,17 @@ func.func @memref_dim(%m: memref<?xf32>) -> index {
// -----
+// CHECK-LABEL: func @memref_dim_all_positive(
+func.func @memref_dim_all_positive(%m: memref<?xf32>, %x: index) {
+ %c0 = arith.constant 0 : index
+ %0 = memref.dim %m, %x : memref<?xf32>
+ // expected-remark @below{{true}}
+ "test.compare"(%0, %c0) {cmp = "GE"} : (index, index) -> ()
+ return
+}
+
+// -----
+
// CHECK-LABEL: func @memref_get_global(
// CHECK: %[[c4:.*]] = arith.constant 4 : index
// CHECK: return %[[c4]]
diff --git a/mlir/test/Dialect/Tensor/value-bounds-op-interface-impl.mlir b/mlir/test/Dialect/Tensor/value-bounds-op-interface-impl.mlir
index c0f64d3c843619..6610d3180cf02d 100644
--- a/mlir/test/Dialect/Tensor/value-bounds-op-interface-impl.mlir
+++ b/mlir/test/Dialect/Tensor/value-bounds-op-interface-impl.mlir
@@ -44,6 +44,17 @@ func.func @dim(%t: tensor<?xf32>) -> index {
// -----
+// CHECK-LABEL: func @dim_all_positive(
+func.func @dim_all_positive(%t: tensor<?xf32>, %x: index) {
+ %c0 = arith.constant 0 : index
+ %0 = tensor.dim %t, %x : tensor<?xf32>
+ // expected-remark @below{{true}}
+ "test.compare"(%0, %c0) {cmp = "GE" } : (index, index) -> ()
+ return
+}
+
+// -----
+
// CHECK-LABEL: func @empty(
// CHECK-SAME: %[[sz:.*]]: index
// CHECK: %[[c6:.*]] = arith.constant 6 : index
More information about the Mlir-commits
mailing list