[llvm] [AMDGPU][Scheduler] Refactor ArchVGPR rematerialization during scheduling (PR #125885)
Jeffrey Byrnes via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 11 10:37:39 PDT 2025
================
@@ -1673,174 +1682,333 @@ bool PreRARematStage::allUsesAvailableAt(const MachineInstr *InstToRemat,
return true;
}
-void PreRARematStage::collectRematerializableInstructions() {
- const SIRegisterInfo *SRI = static_cast<const SIRegisterInfo *>(DAG.TRI);
- for (unsigned I = 0, E = DAG.MRI.getNumVirtRegs(); I != E; ++I) {
- Register Reg = Register::index2VirtReg(I);
- if (!DAG.LIS->hasInterval(Reg))
- continue;
-
- // TODO: Handle AGPR and SGPR rematerialization
- if (!SRI->isVGPRClass(DAG.MRI.getRegClass(Reg)) ||
- !DAG.MRI.hasOneDef(Reg) || !DAG.MRI.hasOneNonDBGUse(Reg))
- continue;
+bool PreRARematStage::hasExcessVGPRs(const GCNRegPressure &RP,
+ unsigned MaxVGPRs,
+ unsigned &ExcessArchVGPRs,
+ bool &AGPRLimited) {
+ unsigned NumAGPRs = RP.getAGPRNum();
+ if (!ST.hasGFX90AInsts() || !NumAGPRs) {
+ // Non-unified RF. We can only reduce ArchVGPR excess pressure at this
+ // point, but still want to identify when there is AGPR excess pressure.
+ bool HasSpill = false;
+ unsigned NumArchVGPRs = RP.getArchVGPRNum();
+ if (NumArchVGPRs > MaxVGPRs) {
+ ExcessArchVGPRs = NumArchVGPRs - MaxVGPRs;
+ HasSpill = true;
+ }
+ if (NumAGPRs > MaxVGPRs) {
+ ExcessArchVGPRs = NumArchVGPRs;
+ AGPRLimited = true;
+ HasSpill = true;
+ }
+ return HasSpill;
+ }
+ if (RP.getVGPRNum(true) > MaxVGPRs) {
----------------
jrbyrnes wrote:
We should also take into account the limits of each of accvgpr and archvgpr.
For example, if we have 262 archgpr and 252 accvgpr, we have 514 vgpr (>= MaxVGPRs of 512 assuming occ lowerbound of 1, gfx942).
This calculatuion determines ExcessArchVGPR = 262 - alignDown(512-252,4) = 2, but we really have ExcessArchVGPR of 6 due to archvgpr limit.
Something like this:
ExceedRF, ExceedArch, ExceedAcc -> ExcessArchVGPRs
{1,1,0} -> arch excess
{1,0,1} -> min (acc excess, arch usage)
{1,1,1} -> max (min (total excess, arch usage), min (acc excess, arch usage), arch excess)
https://github.com/llvm/llvm-project/pull/125885
More information about the llvm-commits
mailing list