[llvm] [AtomicExpandPass][NVPTX] Preserve atomic and volatile nature of emulated operations (PR #188361)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 1 05:23:45 PDT 2026
================
@@ -1163,6 +1164,22 @@ bool AtomicExpandImpl::expandPartwordCmpXchg(AtomicCmpXchgInst *CI) {
PHINode *Loaded_MaskOut = Builder.CreatePHI(PMV.WordType, 2);
Loaded_MaskOut->addIncoming(InitLoaded_MaskOut, BB);
+ // The initial load must be atomic with the same synchronization scope
+ // to avoid a data race with concurrent stores. If the instruction being
+ // emulated is volatile, issue a volatile load.
+ // addIncoming is done first so that expandAtomicLoadToLibcall's
+ // replaceAllUsesWith correctly updates the PHI incoming value.
+ InitLoaded->setVolatile(CI->isVolatile());
+ if (TLI->issueAtomicInitLoadForAtomicEmulation()) {
+ // TODO: Get rid of the target hook once all backends start issuing
+ // atomic loads.
----------------
arsenm wrote:
If you want to introduce the hook and update all the other targets in a separate change, that's fine. But the way these "add hook for targets to update later" always go is it will sit here unimplemented, for many years. We have way too many legacy migrations like this already
https://github.com/llvm/llvm-project/pull/188361
More information about the llvm-commits
mailing list