<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/124768>124768</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MachineCopyProp] WRONG code
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:codegen
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
JonPsson1
</td>
</tr>
</table>
<pre>
[wrong0.tar.gz](https://github.com/user-attachments/files/18575703/wrong0.tar.gz)
llc -mtriple=s390x-linux-gnu -o after-machine-cp.mir -mcpu=z15 -O1 ./wrong0.mir -run-pass=machine-cp
The reduced test case is somewhat silly as it originally involves a select instruction where both source operands hold the same register (the select has been expanded to a cmp/jump, as seen below). Nevertheless, before machine-cp:
```
bb.14.cleanup22.i:
liveins: $r2d, $r4d, $r6d, $r8d, $r10d, $r0h, $r5h, $r1l, $r3l, $r5l, $r12q
renamable $r1l = AHIMuxK killed renamable $r1l, -1, implicit-def dead $cc
CHIMux renamable $r5h, 9, implicit-def $cc
$r14h = COPY killed renamable $r1l
BRC 14, 6, %bb.26, implicit $cc
bb.27.cleanup22.i:
liveins: $r1l, $r2d, $r2l, $r2h, $r4d, $r4l, $r4h, $r6d, $r6l, $r6h, $r8d, $r8l, $r8h, $r10d, $r10l, $r10h, $r0h, $r13h, $r14h, $r3l, $r5l, $r12q, $r12d, $r12l, $r12h, $r13d, $r13l, $r5h, $cc
$r14h = COPY renamable $r1l
bb.26.cleanup22.i:
```
After machine-cp, the COPY is no longer defining $r14h with the AHIMux definition, but with it's source, which seems broken.
```
bb.16.cleanup22.i:
successors: %bb.18(0x40000000), %bb.17(0x40000000)
liveins: $r2d, $r4d, $r6d, $r8d, $r10d, $r0h, $r5h, $r1l, $r3l, $r5l, $r12q
$r14h = AHIMuxK killed renamable $r1l, -1, implicit-def dead $cc
CHIMux renamable $r5h, 9, implicit-def $cc
BRC 14, 6, %bb.18, implicit $cc
bb.17.cleanup22.i:
successors: %bb.18(0x80000000)
liveins: $r1l, $r2d, $r2l, $r2h, $r4d, $r4l, $r4h, $r6d, $r6l, $r6h, $r8d, $r8l, $r8h, $r10d, $r10l, $r10h, $r0h, $r13h, $r14h, $r3l, $r5l, $r12q, $r12d, $r12l, $r12h, $r13d, $r13l, $r5h, $cc
$r14h = COPY renamable $r1l
bb.18.cleanup22.i:
```
@ostannard @nikic @vladimirradosavljevic
This is the same test case as in #124542
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsVkuv2zYT_TX0ZiBBoh6WF144Nvx9bZEHggJFlxQ1FplQpEpS9k1-fUHJV3KufdMHuuiihiEdcIZnRjycwTDnZKsRt6R4Q4rDig1eGLv90egPzhmdrmrTfAnGizW6TWLPbNx-JcWB0Ep43zuS7Qg9EnpspRdDHXPTEXocHNqIec-46FB7R-jxJBWGd1oV62KdZIQev-WkG5LsSLJTikPUeSt7hSQ7uGyTPEVK6uEpavUAkQF28mijjnEhNUa8jztpIep4P5Ds8DUtIHqfQrwEGM120FHPnCPZYdk5RfxZIFhsBo4NeHQeOHMI0oEzHV4E8-CkUl-AOZAejJWt1CwsSH026owOGDhUyD1I7bwduJdGw0WgRaiNF-DMYDmC6dEy3TgQRjXgBYJjXYjdSufRAqHVuDhxCeagRtSATz3TTUjOAAPe9YQePw3htQ85ueBTozIXQjcxvMMzWi9QoXPBo8aTsQg3H53tpu8mZXL9JzuAuo7TPOYKmR56SmM5-QEAKHlGqYPWQGhuaRN4A8pnVM6omlGazDARz6iYUaqeUTajYkYp_W2MHh4WNetYrfC6D0h2gN3_f3g7PP0En6VS2Nz5BJ4oDU_Z9Upy6aMGT9Aga4IH54F4P3K82DtluLnbOu8CmGLkYkxk__7Dr69mMbm_-biHNA-M5fR9RV3HtLwNcUMfHsG-_lNqLMe46EKXNXGvVT5bc3GvXzlbS3GvaTVbK_FA5zRZBFw0X1CaLXAJ_pr-M1z46Y3DDevicMP1bL851jvdHgr2XA-0vFfgm6LZ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