<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62712>62712</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
*** Bad machine code: Illegal virtual register for instruction *** after early-tailduplication
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mikaelholmen
</td>
</tr>
</table>
<pre>
llvm commit: c5dede880d175
Reproduce with: ```llc -verify-machineinstrs -mtriple aarch64-none-linux-gnu -o - bbi-63545-aarch64.mir -run-pass early-tailduplication```
Result:
```
# After Early Tail Duplication
# Machine code for function f: IsSSA, TracksLiveness
bb.0:
successors: %bb.4(0x80000000); %bb.4(100.00%)
$x0 = COPY undef $x0, implicit-def %0:gpr32common
B %bb.4
bb.1:
successors: %bb.4(0x80000000); %bb.4(100.00%)
$x0 = COPY undef $x0, implicit-def %1:gpr32common
B %bb.4
bb.3:
bb.4:
; predecessors: %bb.0, %bb.1
successors: %bb.5(0x50000000), %bb.6(0x30000000); %bb.5(62.50%), %bb.6(37.50%)
%3:gpr32sp = PHI %0:gpr32common, %bb.0, %1:gpr32common, %bb.1
CBNZW %3:gpr32sp, %bb.6
bb.5:
; predecessors: %bb.4
bb.6:
; predecessors: %bb.4
# End machine code for function f.
*** Bad machine code: Illegal virtual register for instruction ***
- function: f
- basic block: %bb.4 (0x9140f00)
- instruction: CBNZW %3:gpr32sp, %bb.6
- operand 0: %3:gpr32sp
Expected a GPR32 register, but got a GPR32sp register
LLVM ERROR: Found 1 machine code errors.
```
So early tail-duplication has changed
```CBNZW %1, %bb.6```
where %1 is a gpr32 vreg into
```CBNZW %3:gpr32sp, %bb.6```
but CBNZW requires a vreg of the class gpr32.
[bbi-63545-aarch64.mir.gz](https://github.com/llvm/llvm-project/files/11475678/bbi-63545-aarch64.mir.gz)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVk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