[llvm] [AMDGPU] Extend DS loop wait optimization with flush point tracking (PR #175658)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 19 23:46:20 PST 2026
================
@@ -3442,22 +3463,41 @@ SIInsertWaitcnts::getPreheaderFlushFlags(MachineLoop *ML,
VgprDefVMEM.insert(RU);
}
}
- // Early exit if both optimizations are invalidated
- if (VMemInvalidated && DSInvalidated)
+ // Early exit if all optimizations are invalidated
+ if (VMemInvalidated && DSInvalidated && FlushPointTrackingInvalid)
return Flags;
}
+ bool IsDSRead = isDSRead(MI);
+ if (IsDSRead && !FlushPointTrackingInvalid)
+ ++DSLoadCount;
+
// DS read vgpr def
// Note: Unlike VMEM, we DON'T invalidate when VgprUse.contains(RegNo).
// If USE comes before DEF, it's the prefetch pattern (use value from
// previous iteration, load for next iteration). We should still flush
// in preheader so iteration 1 doesn't need to wait inside the loop.
// Only invalidate when DEF comes before USE (same-iteration consumption,
// checked above when processing uses).
- if (isDSRead(MI)) {
+ if (IsDSRead || !FlushPointTrackingInvalid) {
for (const MachineOperand &Op : MI.all_defs()) {
+ if (!TRI->isVectorRegister(*MRI, Op.getReg()))
+ continue;
for (MCRegUnit RU : TRI->regunits(Op.getReg().asMCReg())) {
- VgprDefDS.insert(RU);
+ if (IsDSRead)
+ VgprDefDS.insert(RU);
+ // Check for overwrite of pending DS load (flush point) by any
+ // instruction
+ if (!FlushPointTrackingInvalid) {
+ auto It = DSLoadPosition.find(RU);
+ if (It != DSLoadPosition.end()) {
+ if (It->second > LastFlushedPosition)
+ LastFlushedPosition = It->second;
+ if (IsDSRead)
----------------
vporpo wrote:
This if nest is a bit tricky. It seems that if this is a dsload then we need to update DSLoadPosition regardless of whether RU is found in DSLoadPosition. So it would be easier to follow if the insertion into the map was guarded by if (IsDSRead), like:
```
if (IsDSRead)
DSLoadPosition.try_emplace(RU, DSLoadCount);
```
But then we also need to update LastFlushedPosition and avoid a second lookup.
Not sure if there is a better way of writing this, perhaps using the iterator returned by try_emplace()?
https://github.com/llvm/llvm-project/pull/175658
More information about the llvm-commits
mailing list