[Mlir-commits] [mlir] [mlir] disable folding collapse expand to cast (PR #179209)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Feb 4 09:40:26 PST 2026


================
@@ -1385,6 +1385,21 @@ func.func @expand_collapse_do_not_fold_to_cast(%m: memref<1x3x2x384xui8, strided
 
 // -----
 
+// CHECK-LABEL: func @expand_collapse_dynamic_do_not_fold_to_cast(
+//   CHECK-NOT:   memref.cast
+
+func.func @expand_collapse_dynamic_do_not_fold_to_cast(%m: memref<1x?x1x32xsi8, strided<[?, 32, 32, 1]>>, %dyn_size: index)
+    -> (memref<1x1x?x32xsi8, strided<[?, ?, 32, 1]>>)
+  {
+  %0 = memref.collapse_shape %m [[0], [1, 2], [3]]
+      : memref<1x?x1x32xsi8, strided<[?, 32, 32, 1]>> into memref<1x?x32xsi8, strided<[?, 32, 1]>>
+  %1 = memref.expand_shape %0 [[0, 1], [2], [3]] output_shape [1, 1, %dyn_size, 32]
----------------
MaheshRavishankar wrote:

I dont know if this is a valid expand shape. The dimensions have to match. 

Based on the reasssociations
 1 -> 1 x 1
32 -> %dyn_size
1 -> 32.

This seems like this is an illegal expand shape op and should have been caught by the verifier.

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


More information about the Mlir-commits mailing list