[llvm] [AMDGPU] Add DS loop waitcnt optimization for GFX12+ (PR #172728)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 30 08:53:47 PST 2025
================
@@ -2715,51 +2732,105 @@ bool SIInsertWaitcnts::isVMEMOrFlatVMEM(const MachineInstr &MI) const {
return SIInstrInfo::isVMEM(MI);
}
-// Return true if it is better to flush the vmcnt counter in the preheader of
-// the given loop. We currently decide to flush in two situations:
+bool SIInsertWaitcnts::isDSRead(const MachineInstr &MI) const {
+ return SIInstrInfo::isDS(MI) && MI.mayLoad() && !MI.mayStore();
+}
+
+// Check if instruction may store to LDS (including DS stores, atomics,
+// FLAT instructions that may access LDS, and LDS DMA).
+bool SIInsertWaitcnts::mayStoreLDS(const MachineInstr &MI) const {
----------------
hidekisaito wrote:
For the situation #3 (no DS read in the loop), I agree. For the situation #4 (prefetch DS read for the next iter), I also agree if we can assume that we are dealing with well behaving code only. What this code doesn't know is whether the completion of DS read "needs" to wait for "other kinds of LDS stores to finish", e.g., under race condition, and I didn't want to apply the optimization unless I know for sure such (mis)behavior doesn't exist. There may be other ways to ensure safety but I don't have that code. Logic is conservative but not incorrect. We can refine later. Trying to support both aggressive and conservative behaviors through a flag adds unnecessary complexity to the patch. I'd rather stay conservative until a need arises.
https://github.com/llvm/llvm-project/pull/172728
More information about the llvm-commits
mailing list