[llvm] [CodeGen] Mark read_register of allocatable physreg as live-in (PR #200825)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 2 04:13:34 PDT 2026
================
@@ -2544,6 +2544,17 @@ void SelectionDAGISel::Select_READ_REGISTER(SDNode *Op) {
} else {
New =
CurDAG->getCopyFromReg(Op->getOperand(0), dl, Reg, Op->getValueType(0));
+ // Reading an allocatable physical register copies a value that is not
+ // defined in this function. Declare it as a live-in so the resulting COPY
+ // does not use an undefined physical register (which the machine verifier
+ // rejects). Reserved registers (e.g. the stack pointer) are exempt and
+ // need no live-in.
+ MachineFunction &MFn = CurDAG->getMachineFunction();
+ MachineRegisterInfo &MRI = MFn.getRegInfo();
+ const TargetRegisterInfo *TRI = MFn.getSubtarget().getRegisterInfo();
+ if (Reg.isPhysical() && !TRI->getReservedRegs(MFn).test(Reg) &&
+ !MRI.isLiveIn(Reg))
+ MRI.addLiveIn(Reg);
----------------
arsenm wrote:
I think you also need to add this to the live-in of the entry block? But that will still only cover the case in the entry block. It doesn't seem like it's a well formed operation to read from an allocatable register, it could be overwritten at any time. Maybe this should be an error? Or a warning, just lowered with a copy with an undef source
https://github.com/llvm/llvm-project/pull/200825
More information about the llvm-commits
mailing list