[Mlir-commits] [mlir] [mlir] Compose expand of collapse to cast (PR #172864)

Maya Amrami llvmlistbot at llvm.org
Mon Dec 22 23:02:22 PST 2025


================
@@ -1193,6 +1193,42 @@ func.func @collapse_expand_fold_to_cast(%m: memref<?xf32, strided<[1]>, 3>, %sz0
 
 // -----
 
+// CHECK-LABEL: func @expand_collapse_fold_to_cast(
+//  CHECK-SAME:     %[[m:.*]]: memref<1x3x2x384xui8, strided<[1179648, 768, 384, 1]>>
+//       CHECK:   %[[casted:.*]] = memref.cast %[[m]] : memref<1x3x2x384xui8, strided<[1179648, 768, 384, 1]>> to memref<1x3x2x384xui8, strided<[2304, 768, 384, 1]>>
----------------
amrami wrote:

> If you think of access into the memrefs using `sum(index[i] * stride[i])` for the same indices, `%casted` and `%m` are accessing different strides.

Note that the change in `areCastCompatible` allows different strides only if the dim size is 1.
For such indices where the dim is 1, index[i] will always be 0, so index[i] * stride[i] will be 0 and stride[i] can differ between the two memrefs.



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


More information about the Mlir-commits mailing list