Skip to content

Commit b1f9b3d

Browse files
committed
[AMDGPU] Rematerialize VGPR candidates when SGPR spills to VGPR over the VGPR limit
Before, when selecting candidates to rematerialize, we would only consider SGPR candidates when there was an excess of SGPR registers. Failing to eliminate the excess would result in spills to VGPRs. This is normally not an issue, unless spilling to VGPRs results in excess VGPRs. This patch does 2 things: * It relaxes the GCNRPTarget success criteria: now we accept regions where we spill SGPRs to VGPRs, as long as this does not end up in excess VGPRs. * It changes isSaveBeneficial to consider the excess VGPRs (which includes the SGPRs that would be spilled to VGPR). With these changes, the compiler rematerializes VGPRs when the excess SGPRs would result in VGPR excess. This has some unadressed flaws: we should attempt to rematerialize SGPRs first in order to eliminate the SGPR excess that results in VGPR excess. Solves SWDEV-549940
1 parent e331b29 commit b1f9b3d

File tree

4 files changed

+333
-471
lines changed

4 files changed

+333
-471
lines changed

llvm/lib/Target/AMDGPU/GCNRegPressure.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ struct RegExcess {
104104
unsigned AGPR = 0;
105105

106106
bool anyExcess() const { return SGPR || VGPR || ArchVGPR || AGPR; }
107+
bool spillsToMemory() const { return VGPR || ArchVGPR || AGPR; }
107108

108109
RegExcess(const MachineFunction &MF, const GCNRegPressure &RP,
109110
unsigned MaxSGPRs, unsigned MaxVGPRs) {
@@ -415,23 +416,20 @@ bool GCNRPTarget::isSaveBeneficial(Register Reg) const {
415416
const TargetRegisterInfo *TRI = MRI.getTargetRegisterInfo();
416417
const SIRegisterInfo *SRI = static_cast<const SIRegisterInfo *>(TRI);
417418

419+
RegExcess Excess(MF, RP, MaxSGPRs, MaxVGPRs);
420+
418421
if (SRI->isSGPRClass(RC))
419-
return RP.getSGPRNum() > MaxSGPRs;
420-
unsigned NumVGPRs =
421-
SRI->isAGPRClass(RC) ? RP.getAGPRNum() : RP.getArchVGPRNum();
422-
// The addressable limit must always be respected.
423-
if (NumVGPRs > MaxVGPRs)
424-
return true;
425-
// For unified RFs, combined VGPR usage limit must be respected as well.
426-
return UnifiedRF && RP.getVGPRNum(true) > MaxUnifiedVGPRs;
422+
return Excess.SGPR;
423+
424+
if (SRI->isAGPRClass(RC))
425+
return Excess.AGPR;
426+
427+
return Excess.VGPR || Excess.ArchVGPR;
427428
}
428429

429430
bool GCNRPTarget::satisfied() const {
430-
if (RP.getSGPRNum() > MaxSGPRs || RP.getVGPRNum(false) > MaxVGPRs)
431-
return false;
432-
if (UnifiedRF && RP.getVGPRNum(true) > MaxUnifiedVGPRs)
433-
return false;
434-
return true;
431+
RegExcess Excess(MF, RP, MaxSGPRs, MaxVGPRs);
432+
return !Excess.spillsToMemory();
435433
}
436434

437435
///////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)