[Mlir-commits] [mlir] [MLIR] Determine contiguousness of memrefs with dynamic dimensions (PR #142421)

Andrzej WarzyƄski llvmlistbot at llvm.org
Wed Jun 18 11:34:04 PDT 2025


================
@@ -188,9 +188,31 @@ func.func @transfer_read_leading_dynamic_dims(
 
 // -----
 
-// One of the dims to be flattened is dynamic - not supported ATM.
+// The vector could be a non-contiguous slice of the input
+// memref.
 
 func.func @negative_transfer_read_dynamic_dim_to_flatten(
+    %mem : memref<4x?x?x2xi8>) -> vector<2x2x2xi8> {
+
+  %c0 = arith.constant 0 : index
+  %cst = arith.constant 0 : i8
+  %res = vector.transfer_read %mem[%c0, %c0, %c0, %c0], %cst :
+    memref<4x?x?x2xi8>, vector<2x2x2xi8>
+  return %res : vector<2x2x2xi8>
+}
+
+// CHECK-LABEL: func.func @negative_transfer_read_dynamic_dim_to_flatten(
+// CHECK-NOT: memref.collapse_shape
+// CHECK-NOT: vector.shape_cast
+
+// CHECK-128B-LABEL: func @negative_transfer_read_dynamic_dim_to_flatten(
+//   CHECK-128B-NOT:   memref.collapse_shape
+
+// -----
+
+// Can flatten the righmost dynamic dimension
----------------
banach-space wrote:

> Such an explanation of program logic (or in this case, a theorem "from these and these properties it follows the area is contiguous") is in appropriate in a test file.

We do document both _what_ and _why_ (as we see appropriate) in these tests, as covered by MLIR's TestingGuide:
* https://mlir.llvm.org/getting_started/TestingGuide/#test-documentation-best-practices

We may disagree on whether this case requires documentation (I believe that a comment would be beneficial), but in such case, I recommend removing the comment altogether, it adds no new info (it repeats what test function documents).

https://github.com/llvm/llvm-project/pull/142421


More information about the Mlir-commits mailing list