Skip to content

Commit a6326c7

Browse files
committed
Address reviewer comments.
1 parent eec828f commit a6326c7

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,7 +2920,9 @@ bool GCNHazardRecognizer::fixVALUMaskWriteHazard(MachineInstr *MI) {
29202920
return true;
29212921
}
29222922

2923-
static unsigned baseSGPRNumber(Register Reg, const SIRegisterInfo &TRI) {
2923+
// Return the numeric ID 0-63 of an 64b SGPR pair for a given SGPR.
2924+
// i.e. SGPR0 = SGPR0_SGPR1 = 0, SGPR3 = SGPR2_SGPR3 = 1, etc
2925+
static unsigned sgprPairNumber(Register Reg, const SIRegisterInfo &TRI) {
29242926
unsigned RegN = TRI.getEncodingValue(Reg);
29252927
assert(RegN <= 127);
29262928
return (RegN >> 1) & 0x3f;
@@ -2966,13 +2968,14 @@ void GCNHazardRecognizer::computeVALUHazardSGPRs(MachineFunction *MMF) {
29662968
for (auto &MI : reverse(MBB->instrs())) {
29672969
bool IsVALU = SIInstrInfo::isVALU(MI);
29682970
bool IsSALU = SIInstrInfo::isSALU(MI);
2969-
if (!(IsVALU || IsSALU))
2971+
if (!IsVALU && !IsSALU)
29702972
continue;
29712973

29722974
for (const MachineOperand &Op : MI.operands()) {
29732975
if (!Op.isReg())
29742976
continue;
29752977
Register Reg = Op.getReg();
2978+
assert(!Op.getSubReg());
29762979
// Only consider implicit operands of VCC.
29772980
if (Op.isImplicit() && !(Reg == AMDGPU::VCC_LO ||
29782981
Reg == AMDGPU::VCC_HI || Reg == AMDGPU::VCC))
@@ -2981,7 +2984,7 @@ void GCNHazardRecognizer::computeVALUHazardSGPRs(MachineFunction *MMF) {
29812984
continue;
29822985
if (TRI.getEncodingValue(Reg) >= SGPR_NULL)
29832986
continue;
2984-
unsigned RegN = baseSGPRNumber(Reg, TRI);
2987+
unsigned RegN = sgprPairNumber(Reg, TRI);
29852988
if (IsVALU && Op.isUse()) {
29862989
// Note: any access within a cycle must be considered a hazard.
29872990
if (InCycle || (ReadSGPRs[RegN] && SALUWriteSGPRs[RegN]))
@@ -3055,10 +3058,9 @@ bool GCNHazardRecognizer::fixVALUReadSGPRHazard(MachineInstr *MI) {
30553058

30563059
// All SGPR writes before a call/return must be flushed as the callee/caller
30573060
// will not will not see the hazard chain, i.e. (2) to (3) described above.
3058-
const bool IsSetPC = (MI->getOpcode() == AMDGPU::S_SETPC_B64 ||
3059-
MI->getOpcode() == AMDGPU::S_SETPC_B64_return ||
3060-
MI->getOpcode() == AMDGPU::S_SWAPPC_B64 ||
3061-
MI->getOpcode() == AMDGPU::S_CALL_B64);
3061+
const bool IsSetPC = (MI->isCall() || MI->isReturn()) &&
3062+
!(MI->getOpcode() == AMDGPU::S_ENDPGM ||
3063+
MI->getOpcode() == AMDGPU::S_ENDPGM_SAVED);
30623064

30633065
// Collect all SGPR sources for MI which are read by a VALU.
30643066
const unsigned SGPR_NULL = TRI.getEncodingValue(AMDGPU::SGPR_NULL_gfx11plus);
@@ -3081,7 +3083,7 @@ bool GCNHazardRecognizer::fixVALUReadSGPRHazard(MachineInstr *MI) {
30813083
if (TRI.getEncodingValue(OpReg) >= SGPR_NULL)
30823084
continue;
30833085

3084-
unsigned RegN = baseSGPRNumber(OpReg, TRI);
3086+
unsigned RegN = sgprPairNumber(OpReg, TRI);
30853087
if (!VALUReadHazardSGPRs[RegN])
30863088
continue;
30873089

@@ -3102,7 +3104,7 @@ bool GCNHazardRecognizer::fixVALUReadSGPRHazard(MachineInstr *MI) {
31023104
if (IsSetPC && I.getNumDefs() > 0)
31033105
return true;
31043106
// Check for any register writes.
3105-
return llvm::any_of(SGPRsUsed, [this, &I](Register Reg) {
3107+
return any_of(SGPRsUsed, [this, &I](Register Reg) {
31063108
return I.modifiesRegister(Reg, &TRI);
31073109
});
31083110
};
@@ -3123,9 +3125,8 @@ bool GCNHazardRecognizer::fixVALUReadSGPRHazard(MachineInstr *MI) {
31233125
if (!SIInstrInfo::isSALU(I) || SIInstrInfo::isSOPP(I))
31243126
return 0;
31253127
// SALU must be unrelated to any hazard registers.
3126-
if (llvm::any_of(SGPRsUsed, [this, &I](Register Reg) {
3127-
return I.readsRegister(Reg, &TRI);
3128-
}))
3128+
if (any_of(SGPRsUsed,
3129+
[this, &I](Register Reg) { return I.readsRegister(Reg, &TRI); }))
31293130
return 0;
31303131
return 1;
31313132
};
@@ -3147,14 +3148,14 @@ bool GCNHazardRecognizer::fixVALUReadSGPRHazard(MachineInstr *MI) {
31473148
if (Reg == AMDGPU::VCC || Reg == AMDGPU::VCC_LO || Reg == AMDGPU::VCC_HI)
31483149
return Register(AMDGPU::VCC);
31493150
// TODO: handle TTMP?
3150-
return Register(AMDGPU::SGPR0_SGPR1 + baseSGPRNumber(Reg, TRI));
3151+
return Register(AMDGPU::SGPR0_SGPR1 + sgprPairNumber(Reg, TRI));
31513152
};
31523153
auto SearchHazardFn = [this, hazardPair,
31533154
&SGPRsUsed](const MachineInstr &I) {
31543155
if (!SIInstrInfo::isVALU(I))
31553156
return false;
31563157
// Check for any register reads.
3157-
return llvm::any_of(SGPRsUsed, [this, hazardPair, &I](Register Reg) {
3158+
return any_of(SGPRsUsed, [this, hazardPair, &I](Register Reg) {
31583159
return I.readsRegister(hazardPair(Reg), &TRI);
31593160
});
31603161
};

llvm/test/CodeGen/AMDGPU/valu-read-sgpr-hazard.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2-
# RUN: llc -O0 -mtriple=amdgcn -mcpu=gfx1200 -mattr=+wavefrontsize32,-wavefrontsize64 -verify-machineinstrs -run-pass post-RA-hazard-rec -o - %s | FileCheck -check-prefixes=GCN-O0 %s
3-
# RUN: llc -O2 -mtriple=amdgcn -mcpu=gfx1200 -mattr=+wavefrontsize32,-wavefrontsize64 -verify-machineinstrs -run-pass post-RA-hazard-rec -o - %s | FileCheck -check-prefixes=GCN-O2 %s
2+
# RUN: llc -O0 -mtriple=amdgcn -mcpu=gfx1200 -verify-machineinstrs -run-pass post-RA-hazard-rec -o - %s | FileCheck -check-prefixes=GCN-O0 %s
3+
# RUN: llc -O2 -mtriple=amdgcn -mcpu=gfx1200 -verify-machineinstrs -run-pass post-RA-hazard-rec -o - %s | FileCheck -check-prefixes=GCN-O2 %s
44

55
--- |
66
@mem = internal unnamed_addr addrspace(4) constant [4 x <4 x i32>] [<4 x i32> <i32 0, i32 0, i32 0, i32 0>, <4 x i32> <i32 0, i32 0, i32 0, i32 0>, <4 x i32> <i32 0, i32 0, i32 0, i32 0>, <4 x i32> <i32 0, i32 0, i32 0, i32 0>]

0 commit comments

Comments
 (0)