Skip to content

Commit 9d8e538

Browse files
authored
[AMDGPU] Refactor getNonSoftWaitcntOpcode and its callers (#77933)
This avoids listing all soft waitcnt opcodes in two places (getNonSoftWaitcntOpcode and isSoftWaitcnt) and avoids the need for helpers isWaitcnt and isWaitcntVsCnt.
1 parent dec74a8 commit 9d8e538

File tree

3 files changed

+17
-33
lines changed

3 files changed

+17
-33
lines changed

llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -874,11 +874,11 @@ static bool updateOperandIfDifferent(MachineInstr &MI, uint16_t OpName,
874874
}
875875

876876
bool SIInsertWaitcnts::promoteSoftWaitCnt(MachineInstr *Waitcnt) const {
877-
unsigned Opcode = Waitcnt->getOpcode();
878-
if (!SIInstrInfo::isSoftWaitcnt(Opcode))
877+
unsigned Opcode = SIInstrInfo::getNonSoftWaitcntOpcode(Waitcnt->getOpcode());
878+
if (Opcode == Waitcnt->getOpcode())
879879
return false;
880880

881-
Waitcnt->setDesc(TII->get(SIInstrInfo::getNonSoftWaitcntOpcode(Opcode)));
881+
Waitcnt->setDesc(TII->get(Opcode));
882882
return true;
883883
}
884884

@@ -898,10 +898,10 @@ bool SIInsertWaitcnts::applyPreexistingWaitcnt(
898898
if (II.isMetaInstruction())
899899
continue;
900900

901-
unsigned Opcode = II.getOpcode();
902-
bool IsSoft = SIInstrInfo::isSoftWaitcnt(Opcode);
901+
unsigned Opcode = SIInstrInfo::getNonSoftWaitcntOpcode(II.getOpcode());
902+
bool IsSoft = Opcode != II.getOpcode();
903903

904-
if (SIInstrInfo::isWaitcnt(Opcode)) {
904+
if (Opcode == AMDGPU::S_WAITCNT) {
905905
// Update required wait count. If this is a soft waitcnt (= it was added
906906
// by an earlier pass), it may be entirely removed.
907907
unsigned IEnc = II.getOperand(0).getImm();
@@ -918,7 +918,7 @@ bool SIInsertWaitcnts::applyPreexistingWaitcnt(
918918
WaitcntInstr = ⅈ
919919

920920
} else {
921-
assert(SIInstrInfo::isWaitcntVsCnt(Opcode));
921+
assert(Opcode == AMDGPU::S_WAITCNT_VSCNT);
922922
assert(II.getOperand(0).getReg() == AMDGPU::SGPR_NULL);
923923

924924
unsigned OldVSCnt =
@@ -1590,9 +1590,9 @@ bool WaitcntBrackets::merge(const WaitcntBrackets &Other) {
15901590
}
15911591

15921592
static bool isWaitInstr(MachineInstr &Inst) {
1593-
auto Opcode = Inst.getOpcode();
1594-
return SIInstrInfo::isWaitcnt(Opcode) ||
1595-
(SIInstrInfo::isWaitcntVsCnt(Opcode) && Inst.getOperand(0).isReg() &&
1593+
unsigned Opcode = SIInstrInfo::getNonSoftWaitcntOpcode(Inst.getOpcode());
1594+
return Opcode == AMDGPU::S_WAITCNT ||
1595+
(Opcode == AMDGPU::S_WAITCNT_VSCNT && Inst.getOperand(0).isReg() &&
15961596
Inst.getOperand(0).getReg() == AMDGPU::SGPR_NULL);
15971597
}
15981598

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9076,8 +9076,7 @@ bool SIInstrInfo::isAsmOnlyOpcode(int MCOp) const {
90769076
}
90779077

90789078
int SIInstrInfo::pseudoToMCOpcode(int Opcode) const {
9079-
if (SIInstrInfo::isSoftWaitcnt(Opcode))
9080-
Opcode = SIInstrInfo::getNonSoftWaitcntOpcode(Opcode);
9079+
Opcode = SIInstrInfo::getNonSoftWaitcntOpcode(Opcode);
90819080

90829081
unsigned Gen = subtargetEncodingFamily(ST);
90839082

llvm/lib/Target/AMDGPU/SIInstrInfo.h

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -905,29 +905,14 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
905905
}
906906

907907
static unsigned getNonSoftWaitcntOpcode(unsigned Opcode) {
908-
if (isWaitcnt(Opcode))
908+
switch (Opcode) {
909+
case AMDGPU::S_WAITCNT_soft:
909910
return AMDGPU::S_WAITCNT;
910-
911-
if (isWaitcntVsCnt(Opcode))
911+
case AMDGPU::S_WAITCNT_VSCNT_soft:
912912
return AMDGPU::S_WAITCNT_VSCNT;
913-
914-
llvm_unreachable("Expected opcode S_WAITCNT/S_WAITCNT_VSCNT");
915-
}
916-
917-
static bool isWaitcnt(unsigned Opcode) {
918-
return Opcode == AMDGPU::S_WAITCNT || Opcode == AMDGPU::S_WAITCNT_soft;
919-
}
920-
921-
static bool isWaitcntVsCnt(unsigned Opcode) {
922-
return Opcode == AMDGPU::S_WAITCNT_VSCNT ||
923-
Opcode == AMDGPU::S_WAITCNT_VSCNT_soft;
924-
}
925-
926-
// "Soft" waitcnt instructions can be relaxed/optimized out by
927-
// SIInsertWaitcnts.
928-
static bool isSoftWaitcnt(unsigned Opcode) {
929-
return Opcode == AMDGPU::S_WAITCNT_soft ||
930-
Opcode == AMDGPU::S_WAITCNT_VSCNT_soft;
913+
default:
914+
return Opcode;
915+
}
931916
}
932917

933918
bool isVGPRCopy(const MachineInstr &MI) const {

0 commit comments

Comments
 (0)