Skip to content

Commit 47baf50

Browse files
committed
insertwaitcnt pass update for true16
1 parent 56cc929 commit 47baf50

File tree

3 files changed

+44
-20
lines changed

3 files changed

+44
-20
lines changed

llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ enum WaitEventType {
137137
// We reserve a fixed number of VGPR slots in the scoring tables for
138138
// special tokens like SCMEM_LDS (needed for buffer load to LDS).
139139
enum RegisterMapping {
140-
SQ_MAX_PGM_VGPRS = 512, // Maximum programmable VGPRs across all targets.
141-
AGPR_OFFSET = 256, // Maximum programmable ArchVGPRs across all targets.
142-
SQ_MAX_PGM_SGPRS = 256, // Maximum programmable SGPRs across all targets.
143-
NUM_EXTRA_VGPRS = 9, // Reserved slots for DS.
140+
SQ_MAX_PGM_VGPRS = 1024, // Maximum programmable VGPRs across all targets.
141+
AGPR_OFFSET = 512, // Maximum programmable ArchVGPRs across all targets.
142+
SQ_MAX_PGM_SGPRS = 256, // Maximum programmable SGPRs across all targets.
143+
NUM_EXTRA_VGPRS = 9, // Reserved slots for DS.
144144
// Artificial register slots to track LDS writes into specific LDS locations
145145
// if a location is known. When slots are exhausted or location is
146146
// unknown use the first slot. The first slot is also always updated in
@@ -165,6 +165,18 @@ enum VmemType {
165165
NUM_VMEM_TYPES
166166
};
167167

168+
static unsigned getRegPoint(const GCNSubtarget &ST, MCRegister Reg,
169+
const SIRegisterInfo &TRI) {
170+
// Order register interval points so that intervals of 32-bit VGPRs
171+
// include intervals of their 16-bit halves.
172+
MCRegister MCReg = AMDGPU::getMCReg(Reg, ST);
173+
unsigned RegIdx = TRI.getHWRegIndex(MCReg);
174+
bool IsHi = AMDGPU::isHi16Reg(MCReg, TRI);
175+
bool IsVector = TRI.isVectorRegister(MCReg);
176+
assert(isUInt<8>(RegIdx));
177+
return (IsVector ? 0x200 : 0) | (RegIdx << 1) | (IsHi ? 1 : 0);
178+
}
179+
168180
// Maps values of InstCounterType to the instruction that waits on that
169181
// counter. Only used if GCNSubtarget::hasExtendedWaitCounts()
170182
// returns true.
@@ -757,30 +769,31 @@ RegInterval WaitcntBrackets::getRegInterval(const MachineInstr *MI,
757769

758770
RegInterval Result;
759771

760-
unsigned Reg = TRI->getEncodingValue(AMDGPU::getMCReg(Op.getReg(), *ST)) &
761-
AMDGPU::HWEncoding::REG_IDX_MASK;
772+
unsigned Reg = getRegPoint(*ST, Op.getReg(), *TRI);
773+
const TargetRegisterClass *RC = TRI->getPhysRegBaseClass(Op.getReg());
774+
unsigned Size = TRI->getRegSizeInBits(*RC);
762775

776+
// VGPRs are tracked every 16 bits, SGPRs by 32 bits
763777
if (TRI->isVectorRegister(*MRI, Op.getReg())) {
764778
assert(Reg >= Encoding.VGPR0 && Reg <= Encoding.VGPRL);
765779
Result.first = Reg - Encoding.VGPR0;
766780
if (TRI->isAGPR(*MRI, Op.getReg()))
767781
Result.first += AGPR_OFFSET;
768782
assert(Result.first >= 0 && Result.first < SQ_MAX_PGM_VGPRS);
783+
assert(Size % 16 == 0);
784+
Result.second = Result.first + (Size / 16);
769785
} else if (TRI->isSGPRReg(*MRI, Op.getReg())) {
770-
assert(Reg >= Encoding.SGPR0 && Reg < SQ_MAX_PGM_SGPRS);
771-
Result.first = Reg - Encoding.SGPR0 + NUM_ALL_VGPRS;
786+
assert(Reg >= Encoding.SGPR0 && Reg < SQ_MAX_PGM_SGPRS * 2);
787+
Result.first = ((Reg - Encoding.SGPR0) >> 1) + NUM_ALL_VGPRS;
772788
assert(Result.first >= NUM_ALL_VGPRS &&
773789
Result.first < SQ_MAX_PGM_SGPRS + NUM_ALL_VGPRS);
790+
Result.second = Result.first + divideCeil(Size, 32);
774791
}
775792
// TODO: Handle TTMP
776793
// else if (TRI->isTTMP(*MRI, Reg.getReg())) ...
777794
else
778795
return {-1, -1};
779796

780-
const TargetRegisterClass *RC = TRI->getPhysRegBaseClass(Op.getReg());
781-
unsigned Size = TRI->getRegSizeInBits(*RC);
782-
Result.second = Result.first + ((Size + 16) / 32);
783-
784797
return Result;
785798
}
786799

@@ -2452,16 +2465,14 @@ bool SIInsertWaitcnts::runOnMachineFunction(MachineFunction &MF) {
24522465

24532466
unsigned NumVGPRsMax = ST->getAddressableNumVGPRs();
24542467
unsigned NumSGPRsMax = ST->getAddressableNumSGPRs();
2455-
assert(NumVGPRsMax <= SQ_MAX_PGM_VGPRS);
2468+
assert(NumVGPRsMax + AGPR_OFFSET <= SQ_MAX_PGM_VGPRS);
24562469
assert(NumSGPRsMax <= SQ_MAX_PGM_SGPRS);
24572470

24582471
RegisterEncoding Encoding = {};
2459-
Encoding.VGPR0 =
2460-
TRI->getEncodingValue(AMDGPU::VGPR0) & AMDGPU::HWEncoding::REG_IDX_MASK;
2461-
Encoding.VGPRL = Encoding.VGPR0 + NumVGPRsMax - 1;
2462-
Encoding.SGPR0 =
2463-
TRI->getEncodingValue(AMDGPU::SGPR0) & AMDGPU::HWEncoding::REG_IDX_MASK;
2464-
Encoding.SGPRL = Encoding.SGPR0 + NumSGPRsMax - 1;
2472+
Encoding.VGPR0 = getRegPoint(*ST, AMDGPU::VGPR0, *TRI);
2473+
Encoding.VGPRL = Encoding.VGPR0 + NumVGPRsMax * 2 - 1;
2474+
Encoding.SGPR0 = getRegPoint(*ST, AMDGPU::SGPR0, *TRI);
2475+
Encoding.SGPRL = Encoding.SGPR0 + NumSGPRsMax * 2 - 1;
24652476

24662477
BlockInfos.clear();
24672478
bool Modified = false;

llvm/lib/Target/AMDGPU/SIRegisterInfo.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,21 @@ class SIRegisterInfo final : public AMDGPUGenRegisterInfo {
295295
getRegClassForOperandReg(const MachineRegisterInfo &MRI,
296296
const MachineOperand &MO) const;
297297

298+
bool isVGPR(MCRegister Reg) const {
299+
const TargetRegisterClass *RC = getPhysRegBaseClass(Reg);
300+
// Registers without classes are unaddressable, SGPR-like registers.
301+
return RC && isVGPRClass(RC);
302+
}
298303
bool isVGPR(const MachineRegisterInfo &MRI, Register Reg) const;
304+
bool isAGPR(MCRegister Reg) const {
305+
const TargetRegisterClass *RC = getPhysRegBaseClass(Reg);
306+
// Registers without classes are unaddressable, SGPR-like registers.
307+
return RC && isAGPRClass(RC);
308+
}
299309
bool isAGPR(const MachineRegisterInfo &MRI, Register Reg) const;
310+
bool isVectorRegister(MCRegister Reg) const {
311+
return isVGPR(Reg) || isAGPR(Reg);
312+
}
300313
bool isVectorRegister(const MachineRegisterInfo &MRI, Register Reg) const {
301314
return isVGPR(MRI, Reg) || isAGPR(MRI, Reg);
302315
}

llvm/test/CodeGen/AMDGPU/spillv16.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ define void @spill_i16_alu_two_vals() {
6161
; GCN-TRUE16-NEXT: scratch_load_d16_b16 v0, off, s32 offset:4 glc dlc
6262
; GCN-TRUE16-NEXT: s_waitcnt vmcnt(0)
6363
; GCN-TRUE16-NEXT: scratch_load_d16_hi_b16 v0, off, s32 offset:6 ; 2-byte Folded Reload
64-
; GCN-TRUE16-NEXT: s_waitcnt vmcnt(0)
6564
; GCN-TRUE16-NEXT: v_add_nc_u16 v0.l, 0x7b, v0.l
65+
; GCN-TRUE16-NEXT: s_waitcnt vmcnt(0)
6666
; GCN-TRUE16-NEXT: scratch_store_d16_hi_b16 off, v0, s32 dlc
6767
; GCN-TRUE16-NEXT: s_waitcnt_vscnt null, 0x0
6868
; GCN-TRUE16-NEXT: scratch_store_b16 off, v0, s32 offset:4 dlc

0 commit comments

Comments
 (0)