[llvm] [AMDGPU] Refactor GFX11 VALU Mask Hazard Waitcnt Merging (PR #169213)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 13 08:50:34 PDT 2026
================
@@ -437,9 +438,121 @@ class AMDGPUWaitSGPRHazards {
return Changed;
}
+ bool runWaitMerging(MachineFunction &MF) {
+ // Perform per-block merging of existing s_waitcnt_depctr instructions.
+ // Track set of SGPR writes before a given wait instruction, and search
+ // for reads of these SGPRs.
+ // Move the wait to just before the read to improve pipelining.
+ // If no related reads occur before subsequent wait then merged waits.
+ const unsigned ConstantMaskBits = AMDGPU::DepCtr::encodeFieldSaSdst(
+ AMDGPU::DepCtr::encodeFieldVaSdst(
+ AMDGPU::DepCtr::encodeFieldVaVcc(0, *ST), 0),
+ 0);
+ const unsigned VccLoIdx = *sgprNumber(AMDGPU::VCC_LO, *TRI);
+ const unsigned VccHiIdx = *sgprNumber(AMDGPU::VCC_HI, *TRI);
+ bool Changed = false;
+ for (MachineBasicBlock &MBB : MF) {
+ std::bitset<128> WriteSet, PendingSALUWriteSet, PendingVALUWriteSet;
+ MachineInstr *PrevWait = nullptr;
+
+ auto CommitWrites = [&](unsigned Mask) {
+ if (!AMDGPU::DepCtr::decodeFieldSaSdst(Mask))
+ WriteSet |= PendingSALUWriteSet;
+ bool VccLoBit = WriteSet[VccLoIdx];
+ bool VccHiBit = WriteSet[VccHiIdx];
+ if (!AMDGPU::DepCtr::decodeFieldVaSdst(Mask)) {
+ WriteSet |= PendingVALUWriteSet;
+ WriteSet.set(VccLoIdx, VccLoBit);
+ WriteSet.set(VccLoIdx, VccHiBit);
----------------
jayfoad wrote:
Typo?
```suggestion
WriteSet.set(VccHiIdx, VccHiBit);
```
https://github.com/llvm/llvm-project/pull/169213
More information about the llvm-commits
mailing list