[llvm] [ObjCARC] Don't sink objc_retain past releasing atomics (PR #184113)
John McCall via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 2 11:58:12 PST 2026
================
@@ -67,7 +68,15 @@ bool llvm::objcarc::CanDecrementRefCount(const Instruction *Inst,
const Value *Ptr,
ProvenanceAnalysis &PA,
ARCInstKind Class) {
- // First perform a quick check if Class can not touch ref counts.
+ // Atomic RMW and CmpXchg instructions with release or stronger ordering
+ // publish memory to other threads, which may then read the stored pointer and
+ // release it. Treat these as potentially decrementing refcounts.
+ if (const auto *RMW = dyn_cast<AtomicRMWInst>(Inst))
+ return isReleaseOrStronger(RMW->getOrdering());
+ if (const auto *CmpXchg = dyn_cast<AtomicCmpXchgInst>(Inst))
+ return isReleaseOrStronger(CmpXchg->getSuccessOrdering());
----------------
rjmccall wrote:
You need to test both orderings for cmpxchg.
Is this function only used for sinking? If it's also used for hoisting, I think you should probably just use `isStrongerThanMonotonic`.
https://github.com/llvm/llvm-project/pull/184113
More information about the llvm-commits
mailing list