[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:21 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) {
----------------
vporpo wrote:

If I understand correctly the collection of VgprDefDSs is not related to the FlushPointTracking stuff. So doing these together in the same loop nest makes it a bit more complicated to follow. It might be more efficient, but I am not sure it's worth it because we are just iterating over the def RUs, and it comes at the cost of readability, wdyt ?

https://github.com/llvm/llvm-project/pull/175658


More information about the llvm-commits mailing list