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

    <tr>
        <th>Summary</th>
        <td>
            Freezing Physical Regs in Machine Frame Info Removes the Manually Resereved Physical Registers in RegAlloc
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    `llvm::MachineRegisterInfo::freezeReservedRegs` function copies the default reserved registers of the MF's subtarget into the `BitVector` of the MRI's reserved register, as seen here: https://github.com/llvm/llvm-project/blob/5b363483cf2461617fbb2449491c9914811c8d53/llvm/lib/CodeGen/MachineRegisterInfo.cpp#L522-L526

>From my understanding, this does not take into account the manually-reserved physical registers added via `reserveReg`:
https://github.com/llvm/llvm-project/blob/5b363483cf2461617fbb2449491c9914811c8d53/llvm/include/llvm/CodeGen/MachineRegisterInfo.h#L925-L935

Using `reserveReg` to manually constrain register allocater from using specific physical registers fails because `freezeReservedRegs` is called by the register allocator during its initialization, these manually-set registers will be wiped and only the reserved registers designated by the sub target remain:
https://github.com/llvm/llvm-project/blob/e55aa027f813679ca63c9b803690ce792a3d7b28/llvm/lib/CodeGen/RegAllocBase.cpp#L57-L66

Is my understanding correct, or does the assignment operation of the `BitVector` in `freezeReservedRegs` retains the manually-reserved registers? Is ignoring `reserveReg` registers expected behavior? If not, is it possible to make the freezing operation take into account manually reserved physical registers?

cc @arsenm 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8lV1r6zgTxz-NcjO0KPJbfOGLtgc_FFp4COzey9LYnj2yZCQ53ZxPv8h5afa0PbAs7E0SImk08_vPfyRDoMEiNqx4ZMW3jVzi6HwzyUjWS3mUtOmcPjas5MYcJpY9sOzhVaqRLO5xoBDRP9venRZ6j_gD9xjQH1DvcQis5NAvVk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