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

    <tr>
        <th>Summary</th>
        <td>
            [MachineVerifier] Does not report broken livein-list
        </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>
    A test case emerged that seems to be due to an erroneous kill-flag, in the way that a register as live-in while it was killed in the only predecessor of the block:

```
    renamable $r1l = AHIMuxK killed renamable $r1l, -1, implicit-def dead $cc
    $r14l = COPY killed renamable $r1l
    BRC 14, 6, %bb.3, implicit $cc

  bb.2:
    liveins: $r1l

    $r14l = COPY renamable $r1l
```

Even though this may look harmless, this will actually cause Machine Copy Propagation to produce wrong code:

```
    $r14l = AHIMuxK killed renamable $r1l, -1, implicit-def dead $cc
    CHIMux renamable $r5h, 9, implicit-def $cc
    BRC 14, 6, %bb.2, implicit $cc
  
 bb.1:
    successors: %bb.2(0x80000000)
    liveins: $r1l
  
    $r14l = COPY renamable $r1l
 
```

It seems reasonable that MachineVerifier would have helped to detect this case, but it does not. At least for a block with a single predecessor, I think it should check that the register is live out from it..?

The above in a .mir test case:

[tc_badlivein.tar.gz](https://github.com/user-attachments/files/18593401/tc_badlivein.tar.gz)
llc -mtriple=s390x-linux-gnu -o after-machine-cp.mir -mcpu=z15 -O1 ./tc_badlivein.mir -run-pass=machine-cp -verify-machineinstrs

This is related to #124768 

@guy-david  @topperc @arsenm @michaelmaitland 
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVd1u4zYTfRr6ZiBBoiT_XPjCiT_jS4vFBkVRoFfFiBxLrClS4I8d79MXlJx1kE0WvaghSII853A4Z84QvVedIdqy5oE1-wXG0Fu3_cWaZ--tKRetldftDgL5AAI9AQ3kOpIQegzgiQYPw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