[llvm] [AMDGPU] Use wavefront scope for single-wave workgroup synchronization (PR #187673)

Sameer Sahasrabuddhe via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 2 04:56:32 PDT 2026


================
@@ -165,6 +166,19 @@ class SIMemOpInfo final {
     // AGENT scope as a conservatively correct alternative.
     if (this->Scope == SIAtomicScope::CLUSTER && !ST.hasClusters())
       this->Scope = SIAtomicScope::AGENT;
+
+    // When max flat work-group size is at most the wavefront size, the
+    // work-group fits in a single wave, so LLVM workgroup scope matches
+    // wavefront scope. Demote workgroup → wavefront here for fences and for
+    // atomics with ordering stronger than monotonic.
+    if (ScopeDemotionFn && this->Scope == SIAtomicScope::WORKGROUP &&
+        (llvm::isStrongerThan(this->Ordering, AtomicOrdering::Monotonic) ||
----------------
ssahasra wrote:

> Is there a reason why we can't/shouldn't do this for `Monotonic` as well? (and also `Unordered`, although I'm not sure if anyone uses that with our backend)

In fact why should this optimization be limited to a particular kind of operation? Any instruction or function call that specifies workgroup scope can be lowered to wavefront scope, right?

Thankfully, async scope will eventually show up as a member of device scope, so it is immune from this optimization.

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


More information about the llvm-commits mailing list