[Mlir-commits] [mlir] [memref] Support non-scalar copies in `reinterpret_cast` elision (PR #203873)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Fri Jun 19 07:53:03 PDT 2026
================
@@ -29,128 +30,294 @@ using namespace mlir;
namespace {
-/// Returns true if `rc` represents a scalar view (all sizes == 1)
-/// into a memref that has exactly one non-unit dimension located at
-/// either the first or last position (i.e. a "row" or "column").
-///
-/// Examples that return true:
-///
-/// // Row-major slice (last dim is non-unit)
-/// memref.reinterpret_cast %buff to offset: [%off],
-/// sizes: [1, 1, 1], strides: [1, 1, 1]
-/// : memref<1x1x8xi32> to memref<1x1x1xi32>
+//===----------------------------------------------------------------------===//
+// Copy Rewrite Helpers
+//===----------------------------------------------------------------------===//
+
+/// Returns row-major strides for static identity-layout memref type.
+static std::optional<SmallVector<int64_t>> getIdentityStrides(MemRefType type) {
+ if (!type.getLayout().isIdentity() || !type.hasStaticShape())
+ return std::nullopt;
----------------
banach-space wrote:
I would move this condition to `getCopyFromReinterCastInfo` and in this method simply assert:
```suggestion
assert (type.getLayout().isIdentity() && type.hasStaticShape() && "Input type should be static MemRef with identity layout");
```
Basically, this method makes no sense if the input is non-static and non-identity layout. IMO it's fine to expect the users to make sure that these pre-conditions are met.
As for `getCopyFromReinterCastInfo`, requiring static shapes with identity layout is a high-level design constraint, worth documenting there (by moving this condition).
This is a non-blocking comment.
https://github.com/llvm/llvm-project/pull/203873
More information about the Mlir-commits
mailing list