[llvm] [SPIRV] Add handling for `uinc_wrap` and `udec_wrap` atomics (PR #179114)

Lleu Yang via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 4 03:14:34 PST 2026


================
@@ -627,3 +634,26 @@ bool SPIRVTargetLowering::insertLogicalCopyOnResult(
       .constrainAllUses(*STI.getInstrInfo(), *STI.getRegisterInfo(),
                         *STI.getRegBankInfo());
 }
+
+TargetLowering::AtomicExpansionKind
+SPIRVTargetLowering::shouldExpandAtomicRMWInIR(const AtomicRMWInst *RMW) const {
+  switch (RMW->getOperation()) {
+  case AtomicRMWInst::FAdd:
+  case AtomicRMWInst::FSub:
+  case AtomicRMWInst::FMin:
+  case AtomicRMWInst::FMax:
+    return AtomicExpansionKind::None;
+  case AtomicRMWInst::UIncWrap:
+  case AtomicRMWInst::UDecWrap:
+    return AtomicExpansionKind::CmpXChg;
+  default:
+    return TargetLowering::shouldExpandAtomicRMWInIR(RMW);
+  }
+}
+
+TargetLowering::AtomicExpansionKind
+SPIRVTargetLowering::shouldCastAtomicRMWIInIR(AtomicRMWInst *RMWI) const {
+  // Do not cast atomic exchange at all since SPIR-V natively supports
----------------
megakite wrote:

@mgcarrasco So how should we solve [this problem](https://github.com/llvm/llvm-project/pull/179114#discussion_r2762023059)? Are we going to keep current PR's modification (i.e. don't cast at all), or cast for the pointer type and modify the test case? If the former is preferred, I think it could be better to leave a `TODO` or `FIXME` in the comment.

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


More information about the llvm-commits mailing list