Skip to content

Commit edc38a6

Browse files
authored
[AMDGPU] Add option to pre-allocate SGPR spill VGPRs (#70626)
SGPR spill VGPRs are WWM registers so allow them to be allocated by SIPreAllocateWWMRegs pass. This intentionally prevents spilling of these VGPRs when enabled.
1 parent 6428bdd commit edc38a6

File tree

2 files changed

+401
-2
lines changed

2 files changed

+401
-2
lines changed

llvm/lib/Target/AMDGPU/SIPreAllocateWWMRegs.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ using namespace llvm;
2828

2929
#define DEBUG_TYPE "si-pre-allocate-wwm-regs"
3030

31+
static cl::opt<bool>
32+
EnablePreallocateSGPRSpillVGPRs("amdgpu-prealloc-sgpr-spill-vgprs",
33+
cl::init(false), cl::Hidden);
34+
3135
namespace {
3236

3337
class SIPreAllocateWWMRegs : public MachineFunctionPass {
@@ -199,6 +203,10 @@ bool SIPreAllocateWWMRegs::runOnMachineFunction(MachineFunction &MF) {
199203

200204
RegClassInfo.runOnMachineFunction(MF);
201205

206+
bool PreallocateSGPRSpillVGPRs =
207+
EnablePreallocateSGPRSpillVGPRs ||
208+
MF.getFunction().hasFnAttribute("amdgpu-prealloc-sgpr-spill-vgprs");
209+
202210
bool RegsAssigned = false;
203211

204212
// We use a reverse post-order traversal of the control-flow graph to
@@ -215,8 +223,11 @@ bool SIPreAllocateWWMRegs::runOnMachineFunction(MachineFunction &MF) {
215223
MI.getOpcode() == AMDGPU::V_SET_INACTIVE_B64)
216224
RegsAssigned |= processDef(MI.getOperand(0));
217225

218-
if (MI.getOpcode() == AMDGPU::SI_SPILL_S32_TO_VGPR)
219-
continue;
226+
if (MI.getOpcode() == AMDGPU::SI_SPILL_S32_TO_VGPR) {
227+
if (!PreallocateSGPRSpillVGPRs)
228+
continue;
229+
RegsAssigned |= processDef(MI.getOperand(0));
230+
}
220231

221232
if (MI.getOpcode() == AMDGPU::ENTER_STRICT_WWM ||
222233
MI.getOpcode() == AMDGPU::ENTER_STRICT_WQM ||

0 commit comments

Comments
 (0)