Skip to content

Commit d7ecf2d

Browse files
committed
Address feedback
1 parent 7175200 commit d7ecf2d

File tree

2 files changed

+73
-474
lines changed

2 files changed

+73
-474
lines changed

llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2984,36 +2984,35 @@ bool SIRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator MI,
29842984
// Fallback: If we need an SGPR but cannot scavenge one and there is no
29852985
// frame register, try to convert the flat-scratch instruction to use a
29862986
// VGPR index (SS -> SV) and materialize the offset in a VGPR.
2987-
if (!TmpSReg && !FrameReg && TII->isFLATScratch(*MI)) {
2987+
unsigned Opc = MI->getOpcode();
2988+
int NewOpc = AMDGPU::getFlatScratchInstSVfromSS(Opc);
2989+
if (!TmpSReg && !FrameReg && TII->isFLATScratch(*MI) && NewOpc != -1) {
29882990
// Reuse an existing VGPR temp if available, otherwise scavenge one.
29892991
Register VTmp = (!UseSGPR && TmpReg)
29902992
? TmpReg
29912993
: RS->scavengeRegisterBackwards(
2992-
AMDGPU::VGPR_32RegClass, MI, false, 0);
2994+
AMDGPU::VGPR_32RegClass, MI,
2995+
/*RestoreAfter=*/false, /*SPAdj=*/0);
29932996
if (VTmp) {
29942997
// Put the large offset into a VGPR and zero the immediate offset.
29952998
BuildMI(*MBB, MI, DL, TII->get(AMDGPU::V_MOV_B32_e32), VTmp)
29962999
.addImm(Offset);
29973000

2998-
unsigned Opc = MI->getOpcode();
2999-
int NewOpc = AMDGPU::getFlatScratchInstSVfromSS(Opc);
3000-
if (NewOpc != -1) {
3001-
int OldSAddrIdx =
3002-
AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::saddr);
3003-
int NewVAddrIdx =
3004-
AMDGPU::getNamedOperandIdx(NewOpc, AMDGPU::OpName::vaddr);
3005-
if (OldSAddrIdx == NewVAddrIdx && OldSAddrIdx >= 0) {
3006-
MI->setDesc(TII->get(NewOpc));
3007-
// Replace former saddr (now vaddr) with the VGPR index.
3008-
MI->getOperand(NewVAddrIdx).ChangeToRegister(VTmp, false);
3009-
// Reset the immediate offset to 0 as it is now in vaddr.
3010-
MachineOperand *OffOp =
3011-
TII->getNamedOperand(*MI, AMDGPU::OpName::offset);
3012-
assert(OffOp && "Flat scratch SV form must have offset operand");
3013-
OffOp->setImm(0);
3014-
return false;
3015-
}
3016-
}
3001+
int OldSAddrIdx =
3002+
AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::saddr);
3003+
int NewVAddrIdx =
3004+
AMDGPU::getNamedOperandIdx(NewOpc, AMDGPU::OpName::vaddr);
3005+
3006+
assert(OldSAddrIdx >= 0 && NewVAddrIdx >= 0 &&
3007+
"Invalid address operand indexes");
3008+
MI->setDesc(TII->get(NewOpc));
3009+
MI->getOperand(NewVAddrIdx).ChangeToRegister(VTmp, false);
3010+
MachineOperand *OffOp =
3011+
TII->getNamedOperand(*MI, AMDGPU::OpName::offset);
3012+
3013+
assert(OffOp && "Flat scratch SV form must have offset operand");
3014+
OffOp->setImm(0);
3015+
return false;
30173016
}
30183017
}
30193018

0 commit comments

Comments
 (0)