[clang] [llvm] [AMDGPU][GFX12.5] Reimplement monitor load as an atomic operation (PR #177343)

Sameer Sahasrabuddhe via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 22 20:11:37 PST 2026


================
@@ -4204,25 +4204,24 @@ def int_amdgcn_cluster_load_b32         : AMDGPUClusterLoad<global_ptr_ty>;
 def int_amdgcn_cluster_load_b64         : AMDGPUClusterLoad<global_ptr_ty>;
 def int_amdgcn_cluster_load_b128        : AMDGPUClusterLoad<global_ptr_ty>;
 
-class AMDGPULoadMonitor<LLVMType ptr_ty>:
+class AMDGPUAtomicLoadMonitor<LLVMType ptr_ty>:
   Intrinsic<
     [llvm_any_ty],
     [ptr_ty,
-     llvm_i32_ty],  // gfx12+ cachepolicy:
-                    //   bits [0-2] = th
-                    //   bits [3-4] = scope
+     llvm_i32_ty,            // C ABI Atomic Ordering ID
+     llvm_metadata_ty],      // syncscope
     [IntrArgMemOnly, IntrReadMem, ReadOnly<ArgIndex<0>>, NoCapture<ArgIndex<0>>, ImmArg<ArgIndex<1>>,
      IntrWillReturn, IntrConvergent, IntrNoCallback, IntrNoFree],
     "",
-    [SDNPMemOperand]
+    [SDNPMemOperand, SDNPMayLoad]
   >;
 
-def int_amdgcn_flat_load_monitor_b32    : AMDGPULoadMonitor<flat_ptr_ty>;
-def int_amdgcn_flat_load_monitor_b64    : AMDGPULoadMonitor<flat_ptr_ty>;
-def int_amdgcn_flat_load_monitor_b128   : AMDGPULoadMonitor<flat_ptr_ty>;
-def int_amdgcn_global_load_monitor_b32  : AMDGPULoadMonitor<global_ptr_ty>;
-def int_amdgcn_global_load_monitor_b64  : AMDGPULoadMonitor<global_ptr_ty>;
-def int_amdgcn_global_load_monitor_b128 : AMDGPULoadMonitor<global_ptr_ty>;
+def int_amdgcn_flat_atomic_load_monitor_b32    : AMDGPUAtomicLoadMonitor<flat_ptr_ty>;
----------------
ssahasra wrote:

> I see your point, but I'd like to keep atomic to stay consistent with `__atomic` built-ins. It's for semantics, not to match the instruction. My intention is to make the built-in more high level than just a inline asm cosplaying as a built-in kind of thing.

The documentation in this patch literally says that this intrinsic
```
"Corresponds to ``flat_load_monitor_b32/64/128`` (``.b32/64/128`` suffixes) instructions."`
```

That feels like an attempt to cut the cake and eat it too. If this is meant to be high-level, then the whole exercise should start with first defining what is the new high-level concept being introduced, and the semantics of the intrinsics that implement this concept. Otherwise, it really is a just a wrapper around the raw instruction.

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


More information about the cfe-commits mailing list