Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2983,10 +2983,36 @@ bool SIRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator MI,
: RS->scavengeRegisterBackwards(AMDGPU::SReg_32_XM0RegClass,
MI, false, 0, !UseSGPR);

// TODO: for flat scratch another attempt can be made with a VGPR index
// if no SGPRs can be scavenged.
if ((!TmpSReg && !FrameReg) || (!TmpReg && !UseSGPR))
if ((!TmpSReg && !FrameReg) || (!TmpReg && !UseSGPR)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a MIR test for this, there are many samples stressing spill pseudo situations

int SVOpcode = AMDGPU::getFlatScratchInstSVfromSS(MI->getOpcode());
if (ST.hasFlatScratchSVSMode() && SVOpcode != -1) {
Register TmpVGPR = RS->scavengeRegisterBackwards(
AMDGPU::VGPR_32RegClass, MI, false, 0, /*AllowSpill=*/true);

// Materialize the frame register.
auto MIB =
BuildMI(*MBB, MI, DL, TII->get(AMDGPU::V_MOV_B32_e32), TmpVGPR);
if (FrameReg)
MIB.addReg(FrameReg);
else
MIB.addImm(Offset);

// Add the offset to the frame register.
if (FrameReg && Offset)
BuildMI(*MBB, MI, DL, TII->get(AMDGPU::V_ADD_U32_e32), FrameReg)
.addReg(FrameReg, RegState::Kill)
.addImm(Offset);
Comment on lines +3001 to +3004
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this valid? Frame reg is an SGPR, and this is writing to it with a VALU instruction. Offset is also an immediate, and cannot be used in src1 of V_ADD_U32_e32.


BuildMI(*MBB, MI, DL, TII->get(SVOpcode))
.add(MI->getOperand(0)) // $vdata
.addReg(TmpVGPR) // $vaddr
.addImm(0) // Offset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should try to split the constant offset component into the addressing mode, and separately add as required above

.add(*TII->getNamedOperand(*MI, AMDGPU::OpName::cpol));
MI->eraseFromParent();
return true;
}
report_fatal_error("Cannot scavenge register in FI elimination!");
}

if (!TmpSReg) {
// Use frame register and restore it after.
Expand Down
Loading
Loading