<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/64000>64000</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            MLIR, TOSA: Dynamic shape causes tosa-to-linalg to emit invalid ops
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            eric-k256
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mgehre-amd
      </td>
    </tr>
</table>

<pre>
    Running
```
module attributes {torch.debug_module_name = "_lambda"} {
  func.func @forward(%arg0: tensor<2x5xf32>, %arg1: tensor<5xf32>, %arg2: tensor<5xf32>, %arg3: tensor<5xf32>, %arg4: tensor<5xf32>) -> tensor<2x5xf32> {
    %0 = "tosa.const"() <{value = dense<9.99999974E-6> : tensor<1x1xf32>}> : () -> tensor<1x1xf32> 
    %1 = "tosa.reshape"(%arg3) <{new_shape = array<i64: 1, 5>}> : (tensor<5xf32>) -> tensor<1x?xf32> 
    %2 = "tosa.reshape"(%arg4) <{new_shape = array<i64: 1, 5>}> : (tensor<5xf32>) -> tensor<1x?xf32> 
    %3 = "tosa.sub"(%arg0, %1) : (tensor<2x5xf32>, tensor<1x?xf32>) -> tensor<2x5xf32> 
    %4 = "tosa.add"(%2, %0) : (tensor<1x?xf32>, tensor<1x1xf32>) -> tensor<1x?xf32> 
    %5 = "tosa.rsqrt"(%4) : (tensor<1x?xf32>) -> tensor<1x?xf32> 
    %6 = "tosa.mul"(%3, %5) <{shift = 0 : i32}> : (tensor<2x5xf32>, tensor<1x?xf32>) -> tensor<2x5xf32> 
    %7 = "tosa.reshape"(%arg1) <{new_shape = array<i64: 1, 5>}> : (tensor<5xf32>) -> tensor<1x?xf32> 
    %8 = "tosa.mul"(%6, %7) <{shift = 0 : i32}> : (tensor<2x5xf32>, tensor<1x?xf32>) -> tensor<2x5xf32> 
    %9 = "tosa.reshape"(%arg2) <{new_shape = array<i64: 1, 5>}> : (tensor<5xf32>) -> tensor<1x?xf32> 
    %10 = "tosa.add"(%8, %9) : (tensor<2x5xf32>, tensor<1x?xf32>) -> tensor<2x5xf32> 
    return %10 : tensor<2x5xf32>
  }
}
```
with
`mlir-opt -pass-pipeline='builtin.module(func.func(tosa-to-linalg))' file.mlir`
fails with
```
error: 'tensor.empty' op incorrect number of dynamic sizes, has 1, expected 0
    %3 = "tosa.sub"(%arg0, %1) : (tensor<2x5xf32>, tensor<1x?xf32>) -> tensor<2x5xf32> 
         ^
note: see current operation: %5 = "tensor.empty"(%4) : (index) -> tensor<2x5xf32>
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMll2PqzYQhn-Nc2OBjA0BLrjYTTZSpVaVTnu_MjAJbo1N_bGb7a-vDIQNPdmTU6nVFqF8aOx5n3k92HBrxUkBVCh7RJSCEU30O822iFKU7Tfcu06bqj9BZyDifbupdftWffFKCXVCZI_IA9qS-R7_9rr1EjB3zojaO7AY5Y9Om6aLW6j96Xka8Kx4DxixPUaUPkve1y0Povk-jJ9SYXz0qonDB0YpOWrzyk2LaIFoxs2JIPaAHSirDWI7es7OR0YRe0J0h6cRyWrE13F6J87uxNMP4iWOEHu6xXZdHA5ZyMUDpy2PG62sCzaEGkuM2A7ljy9c-smqFpQFxHZlXI5Xnj5F2zHrNUdyTi4k-f4SnTOuud5H4hVUsoIyYDs-wAVrMmahU_D6PMbHOdwY_obYTmxHb5LgVfYVyXdYlpwRO9yEo_fg0k-EYys46-trMDJ3TjIBrtXW_XtT6tuNdY2RrjB42y4YdGYgtxjWYrubLfUPzMjWK2X_MEtvZ-l9_e8X2q6Eei8XGTaXm733hO3E0Y0TyAggGP2gAf7VJcnvtW3yiW1bfGjgdjYw_3QDy3sG0k80MCEfPnHF7GD53z71Bpw3amG5fTLOo0Ph09m9_Fgf4q_CdUugl8JEenA4Gri10SAGkEIBYntE89oL6YSKp1Md0WI5skOZ2vLI6UgKxeUJ0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