Skip to content

Commit 2d9f350

Browse files
authored
[AMDGPU] Consolidate SGPRSpill and VGPRSpill into single Spill bit (#81901)
Follow on to #81525 in the series of consolidating bits in TSFlags. Merge SGPRSpill and VGPRSpill into single Spill bit Modify isSGPRSpill and isVGPRSpill helper functions to differentiate VGPR and SGPR spills: Spill+SALU=SGPR Spill Spill+VALU=VGPR Spill The only exception here is SGPR spills to VGPRs which require an explicit instruction check.
1 parent a4ce870 commit 2d9f350

File tree

5 files changed

+41
-24
lines changed

5 files changed

+41
-24
lines changed

llvm/lib/Target/AMDGPU/SIDefines.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ enum : uint64_t {
8787
FLAT = 1 << 24,
8888
DS = 1 << 25,
8989

90-
// Pseudo instruction formats.
91-
VGPRSpill = 1 << 26,
92-
SGPRSpill = 1 << 27,
90+
// Combined SGPR/VGPR Spill bit
91+
// Logic to separate them out is done in isSGPRSpill and isVGPRSpill
92+
Spill = 1 << 26,
9393

9494
// LDSDIR instruction format.
9595
LDSDIR = 1 << 28,

llvm/lib/Target/AMDGPU/SIInstrFormats.td

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ class InstSI <dag outs, dag ins, string asm = "",
4646
field bit FLAT = 0;
4747
field bit DS = 0;
4848

49-
// Pseudo instruction formats.
50-
field bit VGPRSpill = 0;
51-
field bit SGPRSpill = 0;
49+
// Combined SGPR/VGPR spill bit
50+
field bit Spill = 0;
5251

5352
// LDSDIR instruction format.
5453
field bit LDSDIR = 0;
@@ -187,8 +186,10 @@ class InstSI <dag outs, dag ins, string asm = "",
187186
let TSFlags{24} = FLAT;
188187
let TSFlags{25} = DS;
189188

190-
let TSFlags{26} = VGPRSpill;
191-
let TSFlags{27} = SGPRSpill;
189+
let TSFlags{26} = Spill;
190+
191+
// Reserved, must be 0
192+
let TSFlags{27} = 0;
192193

193194
let TSFlags{28} = LDSDIR;
194195
let TSFlags{29} = VINTERP;

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5424,7 +5424,7 @@ adjustAllocatableRegClass(const GCNSubtarget &ST, const SIRegisterInfo &RI,
54245424
bool IsAllocatable) {
54255425
if ((IsAllocatable || !ST.hasGFX90AInsts() || !MRI.reservedRegsFrozen()) &&
54265426
(((TID.mayLoad() || TID.mayStore()) &&
5427-
!(TID.TSFlags & SIInstrFlags::VGPRSpill)) ||
5427+
!(TID.TSFlags & SIInstrFlags::Spill)) ||
54285428
(TID.TSFlags & (SIInstrFlags::DS | SIInstrFlags::MIMG)))) {
54295429
switch (RCID) {
54305430
case AMDGPU::AV_32RegClassID:
@@ -8809,12 +8809,12 @@ bool SIInstrInfo::isBasicBlockPrologue(const MachineInstr &MI,
88098809
IsNullOrVectorRegister = !RI.isSGPRClass(RI.getRegClassForReg(MRI, Reg));
88108810
}
88118811

8812-
uint16_t Opc = MI.getOpcode();
8812+
uint16_t Opcode = MI.getOpcode();
88138813
// FIXME: Copies inserted in the block prolog for live-range split should also
88148814
// be included.
88158815
return IsNullOrVectorRegister &&
8816-
(isSpillOpcode(Opc) || (!MI.isTerminator() && Opc != AMDGPU::COPY &&
8817-
MI.modifiesRegister(AMDGPU::EXEC, &RI)));
8816+
(isSpill(Opcode) || (!MI.isTerminator() && Opcode != AMDGPU::COPY &&
8817+
MI.modifiesRegister(AMDGPU::EXEC, &RI)));
88188818
}
88198819

88208820
MachineInstrBuilder

llvm/lib/Target/AMDGPU/SIInstrInfo.h

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -708,25 +708,41 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
708708
return get(Opcode).TSFlags & SIInstrFlags::DisableWQM;
709709
}
710710

711+
// SI_SPILL_S32_TO_VGPR and SI_RESTORE_S32_FROM_VGPR form a special case of
712+
// SGPRs spilling to VGPRs which are SGPR spills but from VALU instructions
713+
// therefore we need an explicit check for them since just checking if the
714+
// Spill bit is set and what instruction type it came from misclassifies
715+
// them.
711716
static bool isVGPRSpill(const MachineInstr &MI) {
712-
return MI.getDesc().TSFlags & SIInstrFlags::VGPRSpill;
717+
return MI.getOpcode() != AMDGPU::SI_SPILL_S32_TO_VGPR &&
718+
MI.getOpcode() != AMDGPU::SI_RESTORE_S32_FROM_VGPR &&
719+
(isSpill(MI) && isVALU(MI));
713720
}
714721

715722
bool isVGPRSpill(uint16_t Opcode) const {
716-
return get(Opcode).TSFlags & SIInstrFlags::VGPRSpill;
723+
return Opcode != AMDGPU::SI_SPILL_S32_TO_VGPR &&
724+
Opcode != AMDGPU::SI_RESTORE_S32_FROM_VGPR &&
725+
(isSpill(Opcode) && isVALU(Opcode));
717726
}
718727

719728
static bool isSGPRSpill(const MachineInstr &MI) {
720-
return MI.getDesc().TSFlags & SIInstrFlags::SGPRSpill;
729+
return MI.getOpcode() == AMDGPU::SI_SPILL_S32_TO_VGPR ||
730+
MI.getOpcode() == AMDGPU::SI_RESTORE_S32_FROM_VGPR ||
731+
(isSpill(MI) && isSALU(MI));
721732
}
722733

723734
bool isSGPRSpill(uint16_t Opcode) const {
724-
return get(Opcode).TSFlags & SIInstrFlags::SGPRSpill;
735+
return Opcode == AMDGPU::SI_SPILL_S32_TO_VGPR ||
736+
Opcode == AMDGPU::SI_RESTORE_S32_FROM_VGPR ||
737+
(isSpill(Opcode) && isSALU(Opcode));
725738
}
726739

727-
bool isSpillOpcode(uint16_t Opcode) const {
728-
return get(Opcode).TSFlags &
729-
(SIInstrFlags::SGPRSpill | SIInstrFlags::VGPRSpill);
740+
bool isSpill(uint16_t Opcode) const {
741+
return get(Opcode).TSFlags & SIInstrFlags::Spill;
742+
}
743+
744+
static bool isSpill(const MachineInstr &MI) {
745+
return MI.getDesc().TSFlags & SIInstrFlags::Spill;
730746
}
731747

732748
static bool isWWMRegSpillOpcode(uint16_t Opcode) {

llvm/lib/Target/AMDGPU/SIInstructions.td

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ def V_INDIRECT_REG_READ_GPR_IDX_B32_V16 : V_INDIRECT_REG_READ_GPR_IDX_pseudo<VRe
895895
def V_INDIRECT_REG_READ_GPR_IDX_B32_V32 : V_INDIRECT_REG_READ_GPR_IDX_pseudo<VReg_1024>;
896896

897897
multiclass SI_SPILL_SGPR <RegisterClass sgpr_class> {
898-
let UseNamedOperandTable = 1, SGPRSpill = 1, Uses = [EXEC] in {
898+
let UseNamedOperandTable = 1, Spill = 1, SALU = 1, Uses = [EXEC] in {
899899
def _SAVE : PseudoInstSI <
900900
(outs),
901901
(ins sgpr_class:$data, i32imm:$addr)> {
@@ -931,7 +931,7 @@ defm SI_SPILL_S384 : SI_SPILL_SGPR <SReg_384>;
931931
defm SI_SPILL_S512 : SI_SPILL_SGPR <SReg_512>;
932932
defm SI_SPILL_S1024 : SI_SPILL_SGPR <SReg_1024>;
933933

934-
let SGPRSpill = 1, VALU = 1, isConvergent = 1 in {
934+
let Spill = 1, VALU = 1, isConvergent = 1 in {
935935
def SI_SPILL_S32_TO_VGPR : PseudoInstSI <(outs VGPR_32:$vdst),
936936
(ins SReg_32:$src0, i32imm:$src1, VGPR_32:$vdst_in)> {
937937
let Size = 4;
@@ -951,13 +951,13 @@ def SI_RESTORE_S32_FROM_VGPR : PseudoInstSI <(outs SReg_32:$sdst),
951951
let mayLoad = 0;
952952
let mayStore = 0;
953953
}
954-
} // End SGPRSpill = 1, VALU = 1, isConvergent = 1
954+
} // End Spill = 1, VALU = 1, isConvergent = 1
955955

956956
// VGPR or AGPR spill instructions. In case of AGPR spilling a temp register
957957
// needs to be used and an extra instruction to move between VGPR and AGPR.
958958
// UsesTmp adds to the total size of an expanded spill in this case.
959959
multiclass SI_SPILL_VGPR <RegisterClass vgpr_class, bit UsesTmp = 0> {
960-
let UseNamedOperandTable = 1, VGPRSpill = 1,
960+
let UseNamedOperandTable = 1, Spill = 1, VALU = 1,
961961
SchedRW = [WriteVMEM] in {
962962
def _SAVE : VPseudoInstSI <
963963
(outs),
@@ -983,7 +983,7 @@ multiclass SI_SPILL_VGPR <RegisterClass vgpr_class, bit UsesTmp = 0> {
983983
// Size field is unsigned char and cannot fit more.
984984
let Size = !if(!le(MaxSize, 256), MaxSize, 252);
985985
}
986-
} // End UseNamedOperandTable = 1, VGPRSpill = 1, SchedRW = [WriteVMEM]
986+
} // End UseNamedOperandTable = 1, Spill = 1, VALU = 1, SchedRW = [WriteVMEM]
987987
}
988988

989989
defm SI_SPILL_V32 : SI_SPILL_VGPR <VGPR_32>;

0 commit comments

Comments
 (0)