diff --git a/llvm/lib/Target/AMDGPU/GCNIterativeScheduler.cpp b/llvm/lib/Target/AMDGPU/GCNIterativeScheduler.cpp --- a/llvm/lib/Target/AMDGPU/GCNIterativeScheduler.cpp +++ b/llvm/lib/Target/AMDGPU/GCNIterativeScheduler.cpp @@ -472,7 +472,7 @@ bool TryMaximizeOccupancy) { const auto &ST = MF.getSubtarget(); SIMachineFunctionInfo *MFI = MF.getInfo(); - auto TgtOcc = MFI->getMinAllowedOccupancy(); + auto TgtOcc = MFI->getMinAllowedOccupancy(ST); sortRegionsByPressure(TgtOcc); auto Occ = Regions.front()->MaxPressure.getOccupancy(ST); @@ -560,7 +560,7 @@ bool TryMaximizeOccupancy) { const auto &ST = MF.getSubtarget(); SIMachineFunctionInfo *MFI = MF.getInfo(); - auto TgtOcc = MFI->getMinAllowedOccupancy(); + auto TgtOcc = MFI->getMinAllowedOccupancy(ST); sortRegionsByPressure(TgtOcc); auto Occ = Regions.front()->MaxPressure.getOccupancy(ST); diff --git a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp --- a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp +++ b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp @@ -892,9 +892,9 @@ // Allow memory bound functions to drop to 4 waves if not limited by an // attribute. if (WavesAfter < WavesBefore && WavesAfter < DAG.MinOccupancy && - WavesAfter >= MFI.getMinAllowedOccupancy()) { + WavesAfter >= MFI.getMinAllowedOccupancy(ST)) { LLVM_DEBUG(dbgs() << "Function is memory bound, allow occupancy drop up to " - << MFI.getMinAllowedOccupancy() << " waves\n"); + << MFI.getMinAllowedOccupancy(ST) << " waves\n"); NewOccupancy = WavesAfter; } diff --git a/llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp b/llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp --- a/llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp +++ b/llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp @@ -205,7 +205,7 @@ // operands due to the early clobber we will introduce. Third, the pressure // tracking does not account for the alignment requirements for SGPRs, or the // fragmentation of registers the allocator will need to satisfy. - if (Occupancy >= MFI->getMinAllowedOccupancy() && + if (Occupancy >= MFI->getMinAllowedOccupancy(*ST) && MaxPressure.getVGPRNum(ST->hasGFX90AInsts()) <= MaxVGPRs / 2 && MaxPressure.getSGPRNum() <= MaxSGPRs / 2) { LastRecordedOccupancy = Occupancy; diff --git a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h --- a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h +++ b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h @@ -959,10 +959,13 @@ return Occupancy; } - unsigned getMinAllowedOccupancy() const { + unsigned getMinAllowedOccupancy(const GCNSubtarget &ST) const { if (!isMemoryBound() && !needsWaveLimiter()) return Occupancy; - return (Occupancy < 4) ? Occupancy : 4; + unsigned spillThreshold = ST.getTotalNumVGPRs() / ST.getAddressableNumVGPRs(); + if (spillThreshold < 4) + spillThreshold = 4; + return (Occupancy < spillThreshold) ? Occupancy : spillThreshold; } void limitOccupancy(const MachineFunction &MF);