[Mlir-commits] [mlir] dccb733 - [mlir][MemRef] Return `0` for the canonical strided layout expr of a 0d memref
Benjamin Kramer
llvmlistbot at llvm.org
Tue May 3 02:02:00 PDT 2022
Author: Benjamin Kramer
Date: 2022-05-03T10:58:44+02:00
New Revision: dccb73318a184752491fc1145c4ae01b828bdc3a
URL: https://github.com/llvm/llvm-project/commit/dccb73318a184752491fc1145c4ae01b828bdc3a
DIFF: https://github.com/llvm/llvm-project/commit/dccb73318a184752491fc1145c4ae01b828bdc3a.diff
LOG: [mlir][MemRef] Return `0` for the canonical strided layout expr of a 0d memref
There can't be any strides, and the offset for the canonical expr is
always 0. Fixes #55229.
Differential Revision: https://reviews.llvm.org/D124795
Added:
Modified:
mlir/lib/IR/BuiltinTypes.cpp
mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
Removed:
################################################################################
diff --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp
index d57005237187e..841da97d03f99 100644
--- a/mlir/lib/IR/BuiltinTypes.cpp
+++ b/mlir/lib/IR/BuiltinTypes.cpp
@@ -945,13 +945,11 @@ MemRefType mlir::canonicalizeStridedLayout(MemRefType t) {
AffineExpr mlir::makeCanonicalStridedLayoutExpr(ArrayRef<int64_t> sizes,
ArrayRef<AffineExpr> exprs,
MLIRContext *context) {
- assert(!sizes.empty() && !exprs.empty() &&
- "expected non-empty sizes and exprs");
-
// Size 0 corner case is useful for canonicalizations.
- if (llvm::is_contained(sizes, 0))
+ if (sizes.empty() || llvm::is_contained(sizes, 0))
return getAffineConstantExpr(0, context);
+ assert(!exprs.empty() && "expected exprs");
auto maps = AffineMap::inferFromExprList(exprs);
assert(!maps.empty() && "Expected one non-empty map");
unsigned numDims = maps[0].getNumDims(), nSymbols = maps[0].getNumSymbols();
diff --git a/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir b/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
index 8b215769e0751..84fcea403227e 100644
--- a/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
+++ b/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
@@ -1052,6 +1052,20 @@ func.func @memref_copy_contiguous(%in: memref<16x2xi32>, %offset: index) {
// -----
+// CHECK-LABEL: func @memref_copy_0d_offset
+#map0 = affine_map<(d0) -> (d0 + 1)>
+#map1 = affine_map<() -> (1)>
+func.func @memref_copy_0d_offset(%in: memref<2xi32>) {
+ %buf = memref.alloc() : memref<i32>
+ %sub = memref.subview %in[1] [1] [1] : memref<2xi32> to memref<1xi32, #map0>
+ %scalar = memref.collapse_shape %sub [] : memref<1xi32, #map0> into memref<i32, #map1>
+ memref.copy %scalar, %buf : memref<i32, #map1> to memref<i32>
+ // CHECK: llvm.intr.memcpy
+ return
+}
+
+// -----
+
// CHECK-LABEL: func @memref_copy_noncontiguous
#map = affine_map<(d0, d1)[s0] -> (d0 * 2 + s0 + d1)>
func.func @memref_copy_noncontiguous(%in: memref<16x2xi32>, %offset: index) {
More information about the Mlir-commits
mailing list