Skip to content

Commit c178e63

Browse files
committed
[AMDGPU] Consider FLAT instructions for VMEM hazard detection
In general, "Flat instructions look at the per-workitem address and determine for each work item if the target memory address is in global, private or scratch memory." (RDNA2 ISA) That means that FLAT instructions need to be considered for VMEM hazards even without "specific segment". It should not be needed for DMA VMEM/FLAT instructions, though.
1 parent e55172f commit c178e63

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,9 +1417,8 @@ static bool shouldRunLdsBranchVmemWARHazardFixup(const MachineFunction &MF,
14171417
bool HasVmem = false;
14181418
for (auto &MBB : MF) {
14191419
for (auto &MI : MBB) {
1420-
HasLds |= SIInstrInfo::isDS(MI);
1421-
HasVmem |= (SIInstrInfo::isVMEM(MI) && !SIInstrInfo::isFLAT(MI)) ||
1422-
SIInstrInfo::isSegmentSpecificFLAT(MI);
1420+
HasLds |= SIInstrInfo::isDS(MI) || SIInstrInfo::isLDSDMA(MI);
1421+
HasVmem |= SIInstrInfo::isVMEM(MI) && !SIInstrInfo::isLDSDMA(MI);
14231422
if (HasLds && HasVmem)
14241423
return true;
14251424
}
@@ -1441,10 +1440,9 @@ bool GCNHazardRecognizer::fixLdsBranchVmemWARHazard(MachineInstr *MI) {
14411440
assert(!ST.hasExtendedWaitCounts());
14421441

14431442
auto IsHazardInst = [](const MachineInstr &MI) {
1444-
if (SIInstrInfo::isDS(MI))
1443+
if (SIInstrInfo::isDS(MI) || SIInstrInfo::isLDSDMA(MI))
14451444
return 1;
1446-
if ((SIInstrInfo::isVMEM(MI) && !SIInstrInfo::isFLAT(MI)) ||
1447-
SIInstrInfo::isSegmentSpecificFLAT(MI))
1445+
if (SIInstrInfo::isVMEM(MI) && !SIInstrInfo::isLDSDMA(MI))
14481446
return 2;
14491447
return 0;
14501448
};

llvm/test/CodeGen/AMDGPU/lds-branch-vmem-hazard.mir

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,15 @@ body: |
269269
S_ENDPGM 0
270270
...
271271

272-
# GCN-LABEL: name: no_hazard_lds_branch_flat
272+
# FLAT_* instructions "look at the per-workitem address and determine for each
273+
# work item if the target memory address is in global, private or scratch
274+
# memory" (RDNA2 ISA)
275+
# GCN-LABEL: name: hazard_lds_branch_flat
273276
# GCN: bb.1:
277+
# GFX10-NEXT: S_WAITCNT_VSCNT undef $sgpr_null, 0
274278
# GCN-NEXT: FLAT_LOAD_DWORD
275279
---
276-
name: no_hazard_lds_branch_flat
280+
name: hazard_lds_branch_flat
277281
body: |
278282
bb.0:
279283
successors: %bb.1

0 commit comments

Comments
 (0)