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

Sameer Sahasrabuddhe via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Oct 19 01:05:19 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
----------------
ssahasra wrote:

https://llvm.org/docs/LangRef.html#volatile-memory-accesses

>Fair, on the language side it might make some sense to write a volatile load from the constant addrspace. Then, the question is if, when we lower a volatile load from the constant addrspace to a global_load_..., are we certain enough that no such side-effects happen,

The LangRef allows the addrspace of a volatile to be changed in a target-specific way. As far as I can see, on AMDGPU, volatiles don't actually have any side-effects, so _maybe_ we can lower them to global operations, until one day we can't.

>  or do we actually want to wait for completion after each global_load_... that implements a volatile load, even if it's from constant memory?

The LangRef requires that volatiles cannot be reordered relative to each other, but they can be reordered relative to other memory accesses. So the program will expect us to wait for completion before the next volatile operation. This is independent of whether we change the addrspace or not.

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


More information about the llvm-branch-commits mailing list