<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/117117>117117</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
ComposeExpandOfCollapseOp is not detecting complicated dynamic shapes
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hockyy
</td>
</tr>
</table>
<pre>
```
module {
func.func @broadcast_test(%arg0: tensor<4x8x?x3x?xf32>) -> tensor<1x4x3x8x1x1x?x3x1x1x?x1x14xf32> {
%c2 = arith.constant 2 : index
%c4 = arith.constant 4 : index
%dim = tensor.dim %arg0, %c4 : tensor<4x8x?x3x?xf32>
%dim_0 = tensor.dim %arg0, %c2 : tensor<4x8x?x3x?xf32>
%collapsed = tensor.collapse_shape %arg0 [[0], [1, 2, 3, 4]] : tensor<4x8x?x3x?xf32> into tensor<4x?xf32>
%0 = tensor.empty(%dim_0, %dim) : tensor<4x3x8x?x3x?x14xf32>
%collapsed_1 = tensor.collapse_shape %0 [[0], [1], [2, 3, 4, 5], [6]] : tensor<4x3x8x?x3x?x14xf32> into tensor<4x3x?x14xf32>
%broadcasted = linalg.broadcast ins(%collapsed : tensor<4x?xf32>) outs(%collapsed_1 : tensor<4x3x?x14xf32>) dimensions = [1, 3]
%collapsed_2 = tensor.collapse_shape %broadcasted [[0, 1, 2, 3]] : tensor<4x3x?x14xf32> into tensor<?xf32>
%expanded = tensor.expand_shape %collapsed_2 [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]] output_shape [1, 4, 3, 8, 1, 1, %dim_0, 3, 1, 1, %dim, 1, 14] : tensor<?xf32> into tensor<1x4x3x8x1x1x?x3x1x1x?x1x14xf32>
return %expanded : tensor<1x4x3x8x1x1x?x3x1x1x?x1x14xf32>
}
}
```
```
%collapsed_2 = tensor.collapse_shape %broadcasted [[0, 1, 2, 3]] : tensor<4x3x?x14xf32> into tensor<?xf32>
%expanded = tensor.expand_shape %collapsed_2 [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]] output_shape [1, 4, 3, 8, 1, 1, %dim_0, 3, 1, 1, %dim, 1, 14] : tensor<?xf32> into tensor<1x4x3x8x1x1x?x3x1x1x?x1x14xf32>
```
This part is not canonicalized
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVk2TqjgU_TVhk2qK3IDIgoUf7bY3s7dCEiUzkFAk9OD8-ikiitpov_eWr16VdYHk5t5zzj2ozFp11FLmKFmjZBuwzpWmzUvD_zmdgsKIU44W0fiJtiha1UZ0lcQoXZ-fMT50modDwCiOitYwwZl1eyetQ7BEkLD2GCG6wk5qa1pEN3G_7BHd9dTHAwVE3xFk-A3R9ymL9HFP-2VPejJmX-5IT-Lx2C0QjBEkHDCiW8xa5cqQG20d0w4PiyustJD9fXY8lx0_yRaq9ulniKF_HOnB5lruO6IPFffRNzXhJ2tyU1WssVLc1r0s7m3JGnlpgf3Y1xFKtr5bsibDFYZAhxAPO8n2ewRYaWduU56AuyMr68adzh7xQoyMhaoHNzz0pHddrwaYp74nr8nPMr_e3vKHDU6mncW8Hk-wfRHlFfbrmzMOrlKaVcfwuoyVtmetbge8eqI5ZNh07vGAl2X1ChFkWKhaaquMth7HxRR0oD4vNrwW-47ZKDts8K3Vnqj6Ss0nBpN9w7S4N_95bQJ0h3we0DR72ODFENIhLIeQ-eTzEX-GwEjAdK7p3KXRKFx8rbi8diGT1c-2p3Nb01r8RZ6nr94PfW1OkrXSda1-UG71i-VQOlpkurn_9Zhd_GOm38FMs5P-q1QWN6x1WFmsjcOcaaMVZ5X6T4pA5FRkNGOBzElKgaSwBBqUOUSJAE6WlNKFhJgVnAlCScFpVhQZJIHKIYKYECBRGqURDReHRZIQgIVMSCbjAsWRrJmqwqr6rEPTHgNlbSdzQlJC0qBihays_9cDoOW_2O8iGLQP2nw49FZ0R4viqFLW2amMU66S-cbUjbHy3Xvh47AZPfDRXHgK6SR3Sh8xN3VTKc4Gw4qTZrXi2M_UBl1b5aVzjUV0hWCHYHdUruyKkJsawW7oOV7emtb8LblDsPNILYLdSOUzh_8DAAD__ymCwTA">