[llvm] [AMDGPU][SIInsertWaitcnts] drop OldWaitcntInstr only when it is processed (PR #145720)
Juan Manuel Martinez CaamaƱo via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 30 03:25:39 PDT 2025
================
@@ -2490,7 +2493,6 @@ bool SIInsertWaitcnts::insertWaitcntInBlock(MachineFunction &MF,
// Generate an s_waitcnt instruction to be placed before Inst, if needed.
Modified |= generateWaitcntInstBefore(Inst, ScoreBrackets, OldWaitcntInstr,
FlushVmCnt);
- OldWaitcntInstr = nullptr;
----------------
jmmartinez wrote:
Let me explain what I meant.
- The range between `OldWaitcntInstr` and `Inst` is a range of waits. When we call `generateWaitcntInstBefore`, `Inst` is the first instruction not to be a wait. In `generateWaitcntInstBefore` we call `applyPreexistingWaitcnt` to try to simplify and make the waits "non-soft".
- Before this patch, a meta-instruction used to "break" the sequence of waits between `OldWaitcntInstr` and `Inst` by resetting `OldWaitcntInstr` to `nullptr`. If I understood, this is the main issue this patch is addressing. `generateWaitcntInstBefore` on a meta-instruction just returns `false`.
- With this patch, `generateWaitcntInstBefore` still doesn't do anything on meta-instructions, and we reset `OldWaitcntInstr` to `nullptr` only when we call `applyPreexistingWaitcnt`.
My questions are:
1. Did I understand the problem this patch is trying to solve correctly ?
2. Is there some other case besides meta-instructions where we used to reset `OldWaitcntInstr` when it did not make sense ?
With this in mind, I think that we can try to pull the condition below out of `generateWaitcntInstBefore` and into the loop.
From:
```cpp
// in generateWaitcntInstBefore
if (MI.isMetaInstruction())
return false;
```
To;
```cpp
// in the loop before "if (isWaitInstr(Inst))"
if (MI.isMetaInstruction()) {
++Iter;
continue;
}
```
If we do this, we could keep the unconditional `OldWaitcntInstr = nullptr` after `generateWaitcntInstBefore`. And avoid having this assignment deep in `generateWaitcnt`.
https://github.com/llvm/llvm-project/pull/145720
More information about the llvm-commits
mailing list