From c65d8c71878361d441008a85f0c99305d9e3aff8 Mon Sep 17 00:00:00 2001 From: Guray Ozen Date: Fri, 8 Dec 2023 15:55:14 +0100 Subject: [mlir][memref] extract_strided_metadata for zero-sized memref (#74835) --- mlir/lib/Dialect/Utils/IndexingUtils.cpp | 2 +- .../test/Dialect/MemRef/expand-strided-metadata.mlir | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'mlir') diff --git a/mlir/lib/Dialect/Utils/IndexingUtils.cpp b/mlir/lib/Dialect/Utils/IndexingUtils.cpp index f4e29539..bb8a0d5 100644 --- a/mlir/lib/Dialect/Utils/IndexingUtils.cpp +++ b/mlir/lib/Dialect/Utils/IndexingUtils.cpp @@ -70,7 +70,7 @@ SmallVector delinearizeImpl(ExprType linearIndex, //===----------------------------------------------------------------------===// SmallVector mlir::computeSuffixProduct(ArrayRef sizes) { - assert(llvm::all_of(sizes, [](int64_t s) { return s > 0; }) && + assert(llvm::all_of(sizes, [](int64_t s) { return s >= 0; }) && "sizes must be nonnegative"); int64_t unit = 1; return ::computeSuffixProductImpl(sizes, unit); diff --git a/mlir/test/Dialect/MemRef/expand-strided-metadata.mlir b/mlir/test/Dialect/MemRef/expand-strided-metadata.mlir index ab0c78a..28b7004 100644 --- a/mlir/test/Dialect/MemRef/expand-strided-metadata.mlir +++ b/mlir/test/Dialect/MemRef/expand-strided-metadata.mlir @@ -1494,3 +1494,23 @@ func.func @extract_strided_metadata_of_cast_unranked( index, index, index, index } + + +// ----- +memref.global "private" @dynamicShmem : memref<0xf16,3> + +// CHECK-LABEL: func @zero_sized_memred +func.func @zero_sized_memred(%arg0: f32) -> (memref, index,index,index) { + %c0 = arith.constant 0 : index + %dynamicMem = memref.get_global @dynamicShmem : memref<0xf16, 3> + + // CHECK: %[[BASE:.*]] = memref.get_global @dynamicShmem : memref<0xf16, 3> + // CHECK: %[[CAST:.*]] = memref.reinterpret_cast %[[BASE]] to offset: [0], sizes: [], strides: [] : memref<0xf16, 3> to memref + // CHECK: return %[[CAST]] + + %base_buffer, %offset, %sizes, %strides = memref.extract_strided_metadata %dynamicMem : memref<0xf16, 3> -> memref, index, index, index + return %base_buffer, %offset, + %sizes, %strides : + memref, index, + index, index +} \ No newline at end of file -- cgit v1.1