[Mlir-commits] [mlir] [mlir][memref]: Added OOB value bound check to ViewOp (PR #183985)
Aviad Cohen
llvmlistbot at llvm.org
Sun Mar 1 11:54:08 PST 2026
================
@@ -127,3 +127,214 @@ func.func @memref_subview(%m: memref<?xf32>, %sz: index) -> index {
%1 = "test.reify_bound"(%0) {dim = 0} : (memref<?xf32, strided<[1], offset: 2>>) -> (index)
return %1 : index
}
+
+// -----
+
+// CHECK-LABEL: func @memref_view_static_sizes(
+// CHECK: %[[c64:.*]] = arith.constant 64 : index
+// CHECK: %[[c4:.*]] = arith.constant 4 : index
+// CHECK: return %[[c64]], %[[c4]]
+func.func @memref_view_static_sizes(%raw: memref<2048xi8>, %shift: index) -> (index, index) {
+ %0 = memref.view %raw[%shift][] : memref<2048xi8> to memref<64x4xf32>
+ %1 = "test.reify_bound"(%0) {dim = 0} : (memref<64x4xf32>) -> (index)
+ %2 = "test.reify_bound"(%0) {dim = 1} : (memref<64x4xf32>) -> (index)
+ return %1, %2 : index, index
+}
+
+// -----
+
+// CHECK-LABEL: func @memref_view_dynamic_sizes(
+// CHECK: %[[view:.*]] = memref.view
+// CHECK: return {{.*}}, {{.*}} : index, index
+func.func @memref_view_dynamic_sizes(%raw: memref<?xi8>, %shift: index, %sz0: index, %sz1: index) -> (index, index) {
+ %0 = memref.view %raw[%shift][%sz0, %sz1] : memref<?xi8> to memref<?x?xf32>
+ %1 = "test.reify_bound"(%0) {dim = 0} : (memref<?x?xf32>) -> (index)
+ %2 = "test.reify_bound"(%0) {dim = 1} : (memref<?x?xf32>) -> (index)
+ return %1, %2 : index, index
+}
+
+// -----
+
+// ViewOp OOB (static): 1D view in-bounds. Source 256 bytes, view 64xf32 (64*4=256).
+// test.compare checks OOB on dim 0 (dim == 64).
+// CHECK-LABEL: func @memref_view_oob_static_1d_in_bounds(
+// CHECK: %[[c64:.*]] = arith.constant 64 : index
+// CHECK: return %[[c64]]
+func.func @memref_view_oob_static_1d_in_bounds(%raw: memref<256xi8>, %shift: index) -> index {
+ %c0 = arith.constant 0 : index
+ %c64 = arith.constant 64 : index
+ %0 = memref.view %raw[%shift][] : memref<256xi8> to memref<64xf32>
----------------
AviadCo wrote:
you were right, I removed the trivial static cases and add some dynamic cases instead.
https://github.com/llvm/llvm-project/pull/183985
More information about the Mlir-commits
mailing list