<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62375>62375</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR]`-convert-vector-to-llvm -convert-vector-to-scf ` get stuck in a dead loop, generating infinite SSA values
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
BealZephyr
</td>
</tr>
</table>
<pre>
Test commit: Test commit: https://github.com/llvm/llvm-project/commit/da0730b908a43e490430717beda8486598667ab8
Steps to reproduce:
```
mlir-opt test.mlir -convert-vector-to-llvm -convert-vector-to-scf
```
Test case:
```
module {
func.func @main(%arg0: memref<?x?xf32>, %arg1: memref<?x?x?x?xf32>, %arg2: i1) -> vector<7x14x8x16xf32> {
%0 = llvm.mlir.constant(0 : index) : i64
%c0 = arith.constant 0 : index
%cst = arith.constant dense<0.000000e+00> : vector<14x7x8xf32>
%cst_0 = arith.constant dense<0.000000e+00> : vector<16x7xf32>
%cst_1 = arith.constant dense<0.000000e+00> : vector<7x8x16xf32>
%cst_2 = arith.constant dense<0.000000e+00> : vector<7x8xf32>
%cst_3 = arith.constant dense<0.000000e+00> : vector<8x16xf32>
%1 = llvm.mlir.null : !llvm.ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>>
%2 = llvm.getelementptr %1[1] : (!llvm.ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>>) -> !llvm.ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>>
%3 = llvm.ptrtoint %2 : !llvm.ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>> to i64
%4 = llvm.alloca %3 x !llvm.array<14 x array<7 x array<8 x vector<16xf32>>>> : (i64) -> !llvm.ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>>
%5 = llvm.mlir.undef : !llvm.struct<(ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>>, ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>>, i64)>
%6 = llvm.insertvalue %4, %5[0] : !llvm.struct<(ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>>, ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>>, i64)>
%7 = llvm.insertvalue %4, %6[1] : !llvm.struct<(ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>>, ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>>, i64)>
%8 = llvm.insertvalue %0, %7[2] : !llvm.struct<(ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>>, ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>>, i64)>
%9 = builtin.unrealized_conversion_cast %8 : !llvm.struct<(ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>>, ptr<array<14 x array<7 x array<8 x vector<16xf32>>>>>, i64)> to memref<vector<14x7x8x16xf32>>
%10 = llvm.mlir.null : !llvm.ptr<array<14 x vector<7xi1>>>
%11 = llvm.getelementptr %10[1] : (!llvm.ptr<array<14 x vector<7xi1>>>) -> !llvm.ptr<array<14 x vector<7xi1>>>
%12 = llvm.ptrtoint %11 : !llvm.ptr<array<14 x vector<7xi1>>> to i64
%13 = llvm.alloca %12 x !llvm.array<14 x vector<7xi1>> : (i64) -> !llvm.ptr<array<14 x vector<7xi1>>>
%14 = llvm.mlir.undef : !llvm.struct<(ptr<array<14 x vector<7xi1>>>, ptr<array<14 x vector<7xi1>>>, i64)>
%15 = llvm.insertvalue %13, %14[0] : !llvm.struct<(ptr<array<14 x vector<7xi1>>>, ptr<array<14 x vector<7xi1>>>, i64)>
%16 = llvm.insertvalue %13, %15[1] : !llvm.struct<(ptr<array<14 x vector<7xi1>>>, ptr<array<14 x vector<7xi1>>>, i64)>
%17 = llvm.insertvalue %0, %16[2] : !llvm.struct<(ptr<array<14 x vector<7xi1>>>, ptr<array<14 x vector<7xi1>>>, i64)>
%18 = llvm.mlir.null : !llvm.ptr<array<16 x array<14 x array<7 x vector<8xf32>>>>>
%19 = llvm.getelementptr %18[1] : (!llvm.ptr<array<16 x array<14 x array<7 x vector<8xf32>>>>>) -> !llvm.ptr<array<16 x array<14 x array<7 x vector<8xf32>>>>>
%20 = llvm.ptrtoint %19 : !llvm.ptr<array<16 x array<14 x array<7 x vector<8xf32>>>>> to i64
%21 = llvm.alloca %20 x !llvm.array<16 x array<14 x array<7 x vector<8xf32>>>> : (i64) -> !llvm.ptr<array<16 x array<14 x array<7 x vector<8xf32>>>>>
%22 = llvm.load %21 : !llvm.ptr<array<16 x array<14 x array<7 x vector<8xf32>>>>>
%23 = builtin.unrealized_conversion_cast %22 : !llvm.array<16 x array<14 x array<7 x vector<8xf32>>>> to vector<16x14x7x8xf32>
%24 = vector.transpose %23, [2, 1, 3, 0] : vector<16x14x7x8xf32> to vector<7x14x8x16xf32>
return %24 : vector<7x14x8x16xf32>
}
}
```
The execution seems to be stuck in a dead loop, generating an infinite number of SSA values. An invalid IR segment is shown here, more can be seen in [output.mlir](https://github.com/llvm/llvm-project/files/11329795/output.mlir.txt).
```
...
%11575 = llvm.extractelement %11574[%11 : i64] : vector<8xf32>
%11576 = llvm.insertelement %11575, %8440[%12 : i64] : vector<16xf32>
%11577 = llvm.insertvalue %11576, %11573[0, 6, 4] : !llvm.array<7 x array<14 x array<8 x vector<16xf32>>>>
%11578 = llvm.extractvalue %21[3, 6, 0] : !llvm.array<16 x array<14 x array<7 x vector<8xf32>>>>
%11579 = llvm.extractelement %11578[%10 : i64] : vector<8xf32>
%11580 = llvm.insertelement %11579, %8444[%12 : i64] : vector<16xf32>
%11581 = llvm.insertvalue %11580, %11577[0, 6, 5] : !llvm.array<7 x array<14 x array<8 x vector<16xf32>>>>
%11582 = llvm.extractvalue %21[3, 6, 0] : !llvm.array<16 x array<14 x array<7 x vector<8xf32>>>>
%11583 = llvm.extractelement %11582[%9 : i64] : vector<8xf32>
%11584 = llvm.insertelement %11583, %8448[%12 : i64] : vector<16xf32>
%11585 = llvm.insertvalue %11584, %11581[0, 6, 6] : !llvm.array<7 x array<14 x array<8 x vector<16xf32>>>>
%11586 = llvm.extractvalue %21[3, 6, 0] : !llvm.array<16 x array<14 x array<7 x vector<8xf32>>>>
%11587 = llvm.extractelement %11586[%8 : i64] : vector<8xf32>
%11588 = llvm.insertelement %11587, %8452[%12 : i64] : vector<16xf32>
...
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWUuP4jgX_TVmYxWynZezYAFUI7X0fZvuWc2m5SQX8ExwkO1U0_PrR04CIamkgKIY9UM0RYLv49yT3HNjhDFyowBmKFig4HkiSrst9GwBIv8T9tsfepIU2Y_ZH2AsTovdTlrkzXHvcGvt3iBvjtgKsdVG2m2ZTNNih9gqz1-Of572uvgLUovYqjFlq0yQyCNJTLjwPfBj4nskolECmeA-D4OYh2EkEo7IMyLz-v2rhb3BtsAa9rrIyhRc6HpBSJpXdbjLpX4q9hZjC8ZO3SHGT2mhXkDbpxdIbaGfbPHkshs6b9I1HnRc4xdmPHKRlTlgFC3qY7wuVTp1bxj5ZCekQowjFgi9Ia6CO9hpWCNvibzVwf1fewx5nxBb4noVHVw1tpq51ZIiFuMn5H3CNSTkLaMD9Q_8QMPG5CxDjJ0xwch7xq4gVbmmaaGMFcoixt1XcyxVBgfnuDoI_Y51WpsLLe32ZIrPDTurjR1anoFyhV2SKan-AWILQqpkvXkLhfqH6MCP0Ht-vw0mcq3n8BCN-aV3-I3OK__KM7vT84hb7w63Y-nS3kWiyjyvLBGj1dm9deZCa_GjYgof8PEgOvvM8aFT9SbU-es8LGvDbsBCDjtQdm91lRIKFhQFz00a_OMzOd5Lj8XotRj3VttCKnuE_oDyui7av4f9NgOR50Uq6rQOp-j3xj1S5AL_N0UNetdrqTJYdypqrC5T6zor4x94ySzxhzqrK9ZHF7bopDKg7YvIS6iobBQhQMGCtDfHLwkZdzBHFzGH3YbwG2Dmo5hJgzlCwYL9VpjjCnNSytxKNS2VBpHLfyD7Vg9rRhbqWyqMPdbn14Vti3a86884HfOOEPfHtW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