[llvm] [AMDGPU] Refactor getNonSoftWaitcntOpcode and its callers (PR #77933)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 12 06:00:38 PST 2024
https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/77933
This avoids listing all soft waitcnt opcodes in two places
(getNonSoftWaitcntOpcode and isSoftWaitcnt) and avoids the need for
helpers isWaitcnt and isWaitcntVsCnt.
>From 8c489a4bc2d8ab10b64c641f598e27b2b0630a4b Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Fri, 12 Jan 2024 13:51:41 +0000
Subject: [PATCH] [AMDGPU] Refactor getNonSoftWaitcntOpcode and its callers
This avoids listing all soft waitcnt opcodes in two places
(getNonSoftWaitcntOpcode and isSoftWaitcnt) and avoids the need for
helpers isWaitcnt and isWaitcntVsCnt.
---
llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp | 20 +++++++--------
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 3 +--
llvm/lib/Target/AMDGPU/SIInstrInfo.h | 27 +++++----------------
3 files changed, 17 insertions(+), 33 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
index 1cb1d32707f2d7..a2dbde578fa17e 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -874,11 +874,11 @@ static bool updateOperandIfDifferent(MachineInstr &MI, uint16_t OpName,
}
bool SIInsertWaitcnts::promoteSoftWaitCnt(MachineInstr *Waitcnt) const {
- unsigned Opcode = Waitcnt->getOpcode();
- if (!SIInstrInfo::isSoftWaitcnt(Opcode))
+ unsigned Opcode = SIInstrInfo::getNonSoftWaitcntOpcode(Waitcnt->getOpcode());
+ if (Opcode == Waitcnt->getOpcode())
return false;
- Waitcnt->setDesc(TII->get(SIInstrInfo::getNonSoftWaitcntOpcode(Opcode)));
+ Waitcnt->setDesc(TII->get(Opcode));
return true;
}
@@ -898,10 +898,10 @@ bool SIInsertWaitcnts::applyPreexistingWaitcnt(
if (II.isMetaInstruction())
continue;
- unsigned Opcode = II.getOpcode();
- bool IsSoft = SIInstrInfo::isSoftWaitcnt(Opcode);
+ unsigned Opcode = SIInstrInfo::getNonSoftWaitcntOpcode(II.getOpcode());
+ bool IsSoft = Opcode != II.getOpcode();
- if (SIInstrInfo::isWaitcnt(Opcode)) {
+ if (Opcode == AMDGPU::S_WAITCNT) {
// Update required wait count. If this is a soft waitcnt (= it was added
// by an earlier pass), it may be entirely removed.
unsigned IEnc = II.getOperand(0).getImm();
@@ -918,7 +918,7 @@ bool SIInsertWaitcnts::applyPreexistingWaitcnt(
WaitcntInstr = &II;
} else {
- assert(SIInstrInfo::isWaitcntVsCnt(Opcode));
+ assert(Opcode == AMDGPU::S_WAITCNT_VSCNT);
assert(II.getOperand(0).getReg() == AMDGPU::SGPR_NULL);
unsigned OldVSCnt =
@@ -1589,9 +1589,9 @@ bool WaitcntBrackets::merge(const WaitcntBrackets &Other) {
}
static bool isWaitInstr(MachineInstr &Inst) {
- auto Opcode = Inst.getOpcode();
- return SIInstrInfo::isWaitcnt(Opcode) ||
- (SIInstrInfo::isWaitcntVsCnt(Opcode) && Inst.getOperand(0).isReg() &&
+ unsigned Opcode = SIInstrInfo::getNonSoftWaitcntOpcode(Inst.getOpcode());
+ return Opcode == AMDGPU::S_WAITCNT ||
+ (Opcode == AMDGPU::S_WAITCNT_VSCNT && Inst.getOperand(0).isReg() &&
Inst.getOperand(0).getReg() == AMDGPU::SGPR_NULL);
}
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index d4c7a457e9aae2..5380f6d1fc88f6 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -9065,8 +9065,7 @@ bool SIInstrInfo::isAsmOnlyOpcode(int MCOp) const {
}
int SIInstrInfo::pseudoToMCOpcode(int Opcode) const {
- if (SIInstrInfo::isSoftWaitcnt(Opcode))
- Opcode = SIInstrInfo::getNonSoftWaitcntOpcode(Opcode);
+ Opcode = SIInstrInfo::getNonSoftWaitcntOpcode(Opcode);
unsigned Gen = subtargetEncodingFamily(ST);
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index 37ee159362a28c..daef6031dd0748 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -905,29 +905,14 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
}
static unsigned getNonSoftWaitcntOpcode(unsigned Opcode) {
- if (isWaitcnt(Opcode))
+ switch (Opcode) {
+ case AMDGPU::S_WAITCNT_soft:
return AMDGPU::S_WAITCNT;
-
- if (isWaitcntVsCnt(Opcode))
+ case AMDGPU::S_WAITCNT_VSCNT_soft:
return AMDGPU::S_WAITCNT_VSCNT;
-
- llvm_unreachable("Expected opcode S_WAITCNT/S_WAITCNT_VSCNT");
- }
-
- static bool isWaitcnt(unsigned Opcode) {
- return Opcode == AMDGPU::S_WAITCNT || Opcode == AMDGPU::S_WAITCNT_soft;
- }
-
- static bool isWaitcntVsCnt(unsigned Opcode) {
- return Opcode == AMDGPU::S_WAITCNT_VSCNT ||
- Opcode == AMDGPU::S_WAITCNT_VSCNT_soft;
- }
-
- // "Soft" waitcnt instructions can be relaxed/optimized out by
- // SIInsertWaitcnts.
- static bool isSoftWaitcnt(unsigned Opcode) {
- return Opcode == AMDGPU::S_WAITCNT_soft ||
- Opcode == AMDGPU::S_WAITCNT_VSCNT_soft;
+ default:
+ return Opcode;
+ }
}
bool isVGPRCopy(const MachineInstr &MI) const {
More information about the llvm-commits
mailing list