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

    <tr>
        <th>Summary</th>
        <td>
            [RISCV] Post-PEI MIR testing is broken with Zcmp/libcalls
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:RISC-V
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          francisvm
      </td>
    </tr>
</table>

<pre>
    MIR printing is broken when trying to serialize the output after PrologEpilogInserter (`-run-pass=prologepilog` or `-stop-after`).

`llc -mtriple=riscv32 -mattr=+zcmp -x mir -run-pass=prologepilog -verify-machineinstrs -o - `[zcmp-cm-push-pop.mir](https://github.com/llvm/llvm-project/files/14056737/zcmp-cm-push-pop.mir.txt):

```
Assertion failed: (unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && "Invalid Object Idx!"), function isDeadObjectIndex, file MachineFrameInfo.h, line 747.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
```

Zcmp/save-restore-libcalls have pre-defined frame indices for the saved registers but they're never allocated in `MachineFrameInfo`. When MIRPrinting occurs, the index found in the entries in `MachineFrameInfo::CalleeSavedInfos` is not to be found in `MachineFrameInfo::Objects`, and `isDeadObjectIndex` asserts.

We should create proper (fixed?) slots in MFI in the future to avoid inconsistencies there, since we don't really care about the frame index to be fixed, but the location on the stack.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVUFv4zgP_TXKhbChyIkdH3JIkxoI8PXbogVmgL3JMh1rK0uGKGfS_vqFlATFzE4Pu0DgwLT8SD6-R0sifbKIW7Z-YOvDQs5hcH7be2mVpvO4aF33vn06vsDktQ3ankATtN69oYUfA1oI_j1GgwNCr6XRHwhhQHBzmOYAsg_o4dk7406PkzbudLSEPgaZ2LCSZ3622SSJWHGY0jFMx1jJwXmIJyi4KUtArORM1Dnj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