[llvm-branch-commits] [llvm] [AMDGPU] Extract SIAtomicAddrSpace and fence MMRA parsing from SIMemoryLegalizer (PR #231854)

Fabian Ritter via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Oct 15 05:54:16 PDT 2026


================
@@ -478,4 +480,67 @@ bool isClobberedInFunction(const LoadInst *Load, MemorySSA *MSSA,
   return false;
 }
 
+SIAtomicAddrSpace toSIAtomicAddrSpace(unsigned AS) {
+  if (AS == AMDGPUAS::FLAT_ADDRESS)
+    return SIAtomicAddrSpace::FLAT;
+  if (AS == AMDGPUAS::GLOBAL_ADDRESS)
+    return SIAtomicAddrSpace::GLOBAL;
+  if (AS == AMDGPUAS::LOCAL_ADDRESS)
+    return SIAtomicAddrSpace::LDS;
+  if (AS == AMDGPUAS::PRIVATE_ADDRESS)
+    return SIAtomicAddrSpace::SCRATCH;
+  if (AS == AMDGPUAS::REGION_ADDRESS)
+    return SIAtomicAddrSpace::GDS;
+  if (AS == AMDGPUAS::BUFFER_FAT_POINTER || AS == AMDGPUAS::BUFFER_RESOURCE ||
+      AS == AMDGPUAS::BUFFER_STRIDED_POINTER)
+    return SIAtomicAddrSpace::GLOBAL;
+
+  // Constant addrspaces map to OTHER because there is no point in atomic
----------------
ritter-x2a wrote:

Changed it to be compatible with `isExtendedGlobalAddrSpace`. Treating the constant address spaces as global leads to different waits generated by SIMemoryLegalizer, see the test changes in the current version.
The tests only show changes for volatile loads from the constant addrspace (now we directly wait for them to complete, like for other volatile accesses).
Arguably, these waits are unnecessary since the accessed memory is not supposed to change (which means there is not much sense in doing a volatile load in the first place).

Would it make sense to instead have `GLOBAL_NONCONST` and `GLOBAL_CONST` enum entries in `SIAtomicAddrSpace` (which might be renamed to `MemoryApertureSet`), define `GLOBAL` as `GLOBAL_NONCONST | GLOBAL_CONST`, and map the constant addrspaces to `GLOBAL_CONST`?
Then we could still avoid the waits after `GLOBAL_CONST` volatile loads.

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


More information about the llvm-branch-commits mailing list