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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] Ordering of lowering passes to convert different dialects to llvm may lead to conversion failute
        </td>
    </tr>

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

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          sahas3
      </td>
    </tr>
</table>

<pre>
    Input MLIR in TOSA dialect:

```
module  {
  func @main(%arg0: tensor<1x2x2x3xf32>) -> tensor<1x2x2x3xf32> {
    %0 = "tosa.clamp"(%arg0) {max_fp = 3.40282347E+38 : f32, max_int = 2147483647 : i64, min_fp = 0.000000e+00 : f32, min_int = 0 : i64} : (tensor<1x2x2x3xf32>) -> tensor<1x2x2x3xf32>
    return %0 : tensor<1x2x2x3xf32>
  }
}
```

Pipeline pass to convert to LLVM-IR:
`mlir-opt network.mlir --pass-pipeline="func.func(tosa-infer-shapes, tosa-to-linalg-named, tosa-to-linalg, canonicalize, arith-expand, canonicalize)" --one-shot-bufferize="allow-return-allocs allow-unknown-ops create-deallocs=0" --func-bufferize --pass-pipeline="func.func(canonicalize, convert-linalg-to-affine-loops, affine-loop-fusion, lower-affine, finalizing-bufferize, buffer-deallocation, convert-scf-to-cf, convert-math-to-llvm)" --convert-arith-to-llvm --convert-vector-to-llvm --convert-cf-to-llvm --convert-memref-to-llvm --convert-func-to-llvm --canonicalize --reconcile-unrealized-casts --canonicalize --llvm-legalize-for-export > network-llvm.mlir`

leads to a failure after `--convert-cf-to-llvm`

```
network.mlir:3:10: error: type mismatch for bb argument #0 of successor #0 
%0 = "tosa.clamp"(%arg0) {max_fp = 3.40282347E+38 : f32, max_int = 2147483647 : i64, min_fp = 0.000000e+00 : f32, min_int = 0 : i64} : (tensor<1x2x2x3xf32>) -> tensor<1x2x2x3xf32>                                                                  ^                                                                                                              
network.mlir:3:10: note: see current operation: "llvm.br"(%3)[^bb1] : (i64) -> ()
```

Moving `--convert-cf-to-llvm` after `--convert-func-to-llvm` succeeds. This looks like a bug as ordering of lowering passes shouldn't matter. 

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlVktv4zgM_jXORbDhSHYehxym0ylQoMUsZgd7Xcg2nWgqS4Yk9zG_fknZSTxpp4t93CZNHYukSPEj-dmVbV52t6YfAru_u_3ClGFfP__-gTVKaqhDIj4k-XWSH6-rfPrGZWebQQNjyfpqFDDWDqZmSZF3UpmEbxJeSrfP0Q0LYLx1ifi4fOb4J55bwRPxKeFbluLvz_Rz5xiJlzlLxDXe8GC9zGotux4Xs1joEPd08vnPto-2IityvuGiWGO0K7FhdBzyzj8yMlMmRDu-LNbFRqyKdbRQqyJaKHN0lGd5_AC6yfMf3KDR0U1-2r2-jrd4tn-Z_DlxB2Fw5pj_z9GcNmDoqWKnmx9LN15_Uz1oZYD10nsWLKuteQQX6Pbu7o_79PbLuQNWeaeVS20fmIHwZN1DRgKWprQ77SdfCAHWg_ogowslj4VKlWnBpf4ge_CEWBQGm-IWqfepkR00r-UkqaWxRtVSq-9Aa-lUOKTw3EvTvNZvMTgeyRrAYDak1dBiYFLFc0mt7VM6opnSovZslA3mwdgng_l5VjuQAdIGRgvcmo9uKaOzy79P_fLsE77HrDFP2ba4M9UW48bszmuM5pU1JMUDInqjjtYt7VffldnPEkT5uDgeXIZp-zGsr1uKWbdzYScRTkJcP3Yn_I7KEexJO5M_IjlY94ZijHAh7KBz8JYi4jkTz-DCpQO0q5UGLA5WhKQN2vjgX9uSh1TDPq7TFs-GHWIdjeSnY79Go9i0F3OgQTax_yVrpdKDA6xDAMfQ7q3ULrZfzNZ8OnB8BP4vIwWCczSzOL0vPSBneIS-PjA8LKsq7Ov90AGRCBc5sy3zQ12DxzEfJVOsX4sB2X_-JOX_4OQfBXy_CYwNQL8egNWDc1Rx24MbhzWCxWOfVu5UVUFzWV5hKl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