Skip to content

Commit 06db451

Browse files
committed
Address reviewer comments.
1 parent cf067ec commit 06db451

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
@@ -3012,7 +3012,9 @@ bool GCNHazardRecognizer::fixVALUMaskWriteHazard(MachineInstr *MI) {
30123012
return true;
30133013
}
30143014

3015-
static unsigned baseSGPRNumber(Register Reg, const SIRegisterInfo &TRI) {
3015+
// Return the numeric ID 0-63 of an 64b SGPR pair for a given SGPR.
3016+
// i.e. SGPR0 = SGPR0_SGPR1 = 0, SGPR3 = SGPR2_SGPR3 = 1, etc
3017+
static unsigned sgprPairNumber(Register Reg, const SIRegisterInfo &TRI) {
30163018
unsigned RegN = TRI.getEncodingValue(Reg);
30173019
assert(RegN <= 127);
30183020
return (RegN >> 1) & 0x3f;
@@ -3058,13 +3060,14 @@ void GCNHazardRecognizer::computeVALUHazardSGPRs(MachineFunction *MMF) {
30583060
for (auto &MI : reverse(MBB->instrs())) {
30593061
bool IsVALU = SIInstrInfo::isVALU(MI);
30603062
bool IsSALU = SIInstrInfo::isSALU(MI);
3061-
if (!(IsVALU || IsSALU))
3063+
if (!IsVALU && !IsSALU)
30623064
continue;
30633065

30643066
for (const MachineOperand &Op : MI.operands()) {
30653067
if (!Op.isReg())
30663068
continue;
30673069
Register Reg = Op.getReg();
3070+
assert(!Op.getSubReg());
30683071
// Only consider implicit operands of VCC.
30693072
if (Op.isImplicit() && !(Reg == AMDGPU::VCC_LO ||
30703073
Reg == AMDGPU::VCC_HI || Reg == AMDGPU::VCC))
@@ -3073,7 +3076,7 @@ void GCNHazardRecognizer::computeVALUHazardSGPRs(MachineFunction *MMF) {
30733076
continue;
30743077
if (TRI.getEncodingValue(Reg) >= SGPR_NULL)
30753078
continue;
3076-
unsigned RegN = baseSGPRNumber(Reg, TRI);
3079+
unsigned RegN = sgprPairNumber(Reg, TRI);
30773080
if (IsVALU && Op.isUse()) {
30783081
// Note: any access within a cycle must be considered a hazard.
30793082
if (InCycle || (ReadSGPRs[RegN] && SALUWriteSGPRs[RegN]))
@@ -3147,10 +3150,9 @@ bool GCNHazardRecognizer::fixVALUReadSGPRHazard(MachineInstr *MI) {
31473150

31483151
// All SGPR writes before a call/return must be flushed as the callee/caller
31493152
// will not will not see the hazard chain, i.e. (2) to (3) described above.
3150-
const bool IsSetPC = (MI->getOpcode() == AMDGPU::S_SETPC_B64 ||
3151-
MI->getOpcode() == AMDGPU::S_SETPC_B64_return ||
3152-
MI->getOpcode() == AMDGPU::S_SWAPPC_B64 ||
3153-
MI->getOpcode() == AMDGPU::S_CALL_B64);
3153+
const bool IsSetPC = (MI->isCall() || MI->isReturn()) &&
3154+
!(MI->getOpcode() == AMDGPU::S_ENDPGM ||
3155+
MI->getOpcode() == AMDGPU::S_ENDPGM_SAVED);
31543156

31553157
// Collect all SGPR sources for MI which are read by a VALU.
31563158
const unsigned SGPR_NULL = TRI.getEncodingValue(AMDGPU::SGPR_NULL_gfx11plus);
@@ -3173,7 +3175,7 @@ bool GCNHazardRecognizer::fixVALUReadSGPRHazard(MachineInstr *MI) {
31733175
if (TRI.getEncodingValue(OpReg) >= SGPR_NULL)
31743176
continue;
31753177

3176-
unsigned RegN = baseSGPRNumber(OpReg, TRI);
3178+
unsigned RegN = sgprPairNumber(OpReg, TRI);
31773179
if (!VALUReadHazardSGPRs[RegN])
31783180
continue;
31793181

@@ -3194,7 +3196,7 @@ bool GCNHazardRecognizer::fixVALUReadSGPRHazard(MachineInstr *MI) {
31943196
if (IsSetPC && I.getNumDefs() > 0)
31953197
return true;
31963198
// Check for any register writes.
3197-
return llvm::any_of(SGPRsUsed, [this, &I](Register Reg) {
3199+
return any_of(SGPRsUsed, [this, &I](Register Reg) {
31983200
return I.modifiesRegister(Reg, &TRI);
31993201
});
32003202
};
@@ -3215,9 +3217,8 @@ bool GCNHazardRecognizer::fixVALUReadSGPRHazard(MachineInstr *MI) {
32153217
if (!SIInstrInfo::isSALU(I) || SIInstrInfo::isSOPP(I))
32163218
return 0;
32173219
// SALU must be unrelated to any hazard registers.
3218-
if (llvm::any_of(SGPRsUsed, [this, &I](Register Reg) {
3219-
return I.readsRegister(Reg, &TRI);
3220-
}))
3220+
if (any_of(SGPRsUsed,
3221+
[this, &I](Register Reg) { return I.readsRegister(Reg, &TRI); }))
32213222
return 0;
32223223
return 1;
32233224
};
@@ -3239,14 +3240,14 @@ bool GCNHazardRecognizer::fixVALUReadSGPRHazard(MachineInstr *MI) {
32393240
if (Reg == AMDGPU::VCC || Reg == AMDGPU::VCC_LO || Reg == AMDGPU::VCC_HI)
32403241
return Register(AMDGPU::VCC);
32413242
// TODO: handle TTMP?
3242-
return Register(AMDGPU::SGPR0_SGPR1 + baseSGPRNumber(Reg, TRI));
3243+
return Register(AMDGPU::SGPR0_SGPR1 + sgprPairNumber(Reg, TRI));
32433244
};
32443245
auto SearchHazardFn = [this, hazardPair,
32453246
&SGPRsUsed](const MachineInstr &I) {
32463247
if (!SIInstrInfo::isVALU(I))
32473248
return false;
32483249
// Check for any register reads.
3249-
return llvm::any_of(SGPRsUsed, [this, hazardPair, &I](Register Reg) {
3250+
return any_of(SGPRsUsed, [this, hazardPair, &I](Register Reg) {
32503251
return I.readsRegister(hazardPair(Reg), &TRI);
32513252
});
32523253
};

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)