diff --git a/mlir/lib/Dialect/MemRef/IR/ValueBoundsOpInterfaceImpl.cpp b/mlir/lib/Dialect/MemRef/IR/ValueBoundsOpInterfaceImpl.cpp index daec22cf6ebdc..11400de35e430 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(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 06f2c16406d3c..5bb6259dd543d 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(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 dc311c6b59ea4..8bd7ae8df9049 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) -> index { // ----- +// CHECK-LABEL: func @memref_dim_all_positive( +func.func @memref_dim_all_positive(%m: memref, %x: index) { + %c0 = arith.constant 0 : index + %0 = memref.dim %m, %x : memref + // 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 c0f64d3c84361..6610d3180cf02 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) -> index { // ----- +// CHECK-LABEL: func @dim_all_positive( +func.func @dim_all_positive(%t: tensor, %x: index) { + %c0 = arith.constant 0 : index + %0 = tensor.dim %t, %x : tensor + // 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