<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63294>63294</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[NVPTX] Possible Infinite Loop introduced by `[NVPTX] Allow using v4i32 for memcpy lowering.`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
justinfargnoli
</td>
</tr>
</table>
<pre>
I believe that I've found an infinite loop introduced by [[NVPTX] Allow using v4i32 for memcpy lowering.](https://github.com/llvm/llvm-project/commit/c16b7e54ac5b).
Pinging @Artem-B the author of that commit.
The following input causes `llc` to timeout in [Compiler Explorer](https://godbolt.org/):
```
define <5 x i32> @and3_i32v(<5 x i32> %a, <5 x i32> %b) #0 {
%cmp0 = icmp eq <5 x i32> %a, <i32 1, i32 2, i32 3, i32 4, i32 5>
%cmp1 = icmp eq <5 x i32> %b, <i32 2, i32 3, i32 4, i32 5, i32 6>
%sel = select <5 x i1> %cmp1, <5 x i32> %a, <5 x i32> %b
%sel2 = select <5 x i1> %cmp0, <5 x i32> %sel, <5 x i32> %b
ret <5 x i32> %sel2
}
```
I was also able to observe the infinite loop on my local (modified) fork of LLVM.
This seems to be the code that's causing the infinite loop ([link to the source code](https://github.com/llvm/llvm-project/blob/cdcbef1b14582f5b5b296bec750f60a1629ecc32/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp#L3410)):
```
// We care about the legality of the operation after it has been type
// legalized.
while (TLI.getTypeAction(Ctx, VT) != TargetLoweringBase::TypeLegal)
VT = TLI.getTypeToTransformTo(Ctx, VT);
```
When debugging the code I saw that `getTypeToTransformTo` would always set `VT` to `MVT::v4i32` because of "[NVPTX] Allow using v4i32 for memcpy lowering.". Yet, `getTypeAction(Ctx, MVT::v4i32)` returns `TypeSplitVector`, not `TypeLegal`. Thus, causing an infinite loop.
CC @jholewinski NVPTX code owner.
</p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