Skip to content

Commit 0b82415

Browse files
authored
[AMDGPU] Consider FLAT instructions for VMEM hazard detection (#137170)
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". Also, LDS DMA should be considered for LDS hazard detection. See also #137148
1 parent 3cf1f0c commit 0b82415

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,9 +1502,8 @@ static bool shouldRunLdsBranchVmemWARHazardFixup(const MachineFunction &MF,
15021502
bool HasVmem = false;
15031503
for (auto &MBB : MF) {
15041504
for (auto &MI : MBB) {
1505-
HasLds |= SIInstrInfo::isDS(MI);
1506-
HasVmem |= (SIInstrInfo::isVMEM(MI) && !SIInstrInfo::isFLAT(MI)) ||
1507-
SIInstrInfo::isSegmentSpecificFLAT(MI);
1505+
HasLds |= SIInstrInfo::isDS(MI) || SIInstrInfo::isLDSDMA(MI);
1506+
HasVmem |= SIInstrInfo::isVMEM(MI);
15081507
if (HasLds && HasVmem)
15091508
return true;
15101509
}
@@ -1526,10 +1525,9 @@ bool GCNHazardRecognizer::fixLdsBranchVmemWARHazard(MachineInstr *MI) {
15261525
assert(!ST.hasExtendedWaitCounts());
15271526

15281527
auto IsHazardInst = [](const MachineInstr &MI) {
1529-
if (SIInstrInfo::isDS(MI))
1528+
if (SIInstrInfo::isDS(MI) || SIInstrInfo::isLDSDMA(MI))
15301529
return 1;
1531-
if ((SIInstrInfo::isVMEM(MI) && !SIInstrInfo::isFLAT(MI)) ||
1532-
SIInstrInfo::isSegmentSpecificFLAT(MI))
1530+
if (SIInstrInfo::isVMEM(MI))
15331531
return 2;
15341532
return 0;
15351533
};

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

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

272-
# GCN-LABEL: name: no_hazard_lds_branch_flat
272+
# GCN-LABEL: name: hazard_lds_branch_flat
273273
# GCN: bb.1:
274+
# GFX10-NEXT: S_WAITCNT_VSCNT undef $sgpr_null, 0
274275
# GCN-NEXT: FLAT_LOAD_DWORD
275276
---
276-
name: no_hazard_lds_branch_flat
277+
name: hazard_lds_branch_flat
277278
body: |
278279
bb.0:
279280
successors: %bb.1

0 commit comments

Comments
 (0)