[llvm] [AMDGPU] Add DS loop waitcnt optimization for GFX12+ (PR #172728)

via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 31 10:15:22 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:

>What am I missing in this picture?
No, you aren't missing anything here. We are just on the opposite side on whether or not the optimization should be applied to the cases where the code may look working "just by chance", in this case, just by waiting long enough. I agree with you if apps are well behaving. It's just that I've seen enough of misbehaving code in the past and compiler gets a blame until compiler has a proof of innocence. Yes, I'm a paranoid.

If you insist, I'm fine ditching such conservatism here. I'll just say timing related bugs are super hard to analyze if it occurs and we may not be the ones analyzing it. I'll rework the code here, according to your comment.

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


More information about the llvm-commits mailing list