[llvm] [AMDGPU] Add legalization rules for G_ATOMICRMW_FADD (PR #175257)

Petar Avramovic via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 19 02:44:10 PST 2026


================
@@ -932,6 +932,17 @@ RegBankLegalizeRules::RegBankLegalizeRules(const GCNSubtarget &_ST,
       .Any({{B64, Ptr32}, {{}, {VgprB64, VgprPtr32}}})
       .Any({{B96, Ptr32}, {{}, {VgprB96, VgprPtr32}}})
       .Any({{B128, Ptr32}, {{}, {VgprB128, VgprPtr32}}});
+
+  // Atomics always operate per-lane; keep both the pointer and the value/result
+  // in VGPRs regardless of uniformity. Use Ptr32/Ptr64 to cover all addrspaces
+  // (e.g. local/region/private for Ptr32, global/flat for Ptr64).
+  addRulesForGOpcs({G_ATOMICRMW_FADD})
+      .Any({{B32, Ptr32, B32}, {{VgprB32}, {VgprPtr32, VgprB32}}})
----------------
petar-avramovic wrote:

> keep result in VGPRs regardless of uniformity

For the context of RegBankLegalize this is not correct if it was actually uniform result, it would crash somewhere. Missed this in https://github.com/llvm/llvm-project/pull/175253 also.
Think that atomics are always divergent and inputs can be uniform. Can you check this?
This is most probably should use S types (S32 S64 V2S16) not B type, since B32 includes S32, V2S16, ptr32 etc

Should move the rule to similar opcodes, atomics or fp opcodes, shouldn't be in between loads.

Also if this is Ptr32, should add .ll tests for local/region/private etc.


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


More information about the llvm-commits mailing list