[llvm] [AA] A conservative fix for atomic store instruction. (PR #155032)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 4 09:34:48 PDT 2025


================
@@ -421,9 +421,18 @@ ModRefInfo AAResults::getModRefInfo(const LoadInst *L,
                                     const MemoryLocation &Loc,
                                     AAQueryInfo &AAQI) {
   // Be conservative in the face of atomic.
-  if (isStrongerThan(L->getOrdering(), AtomicOrdering::Unordered))
+  if (isStrongerThan(L->getOrdering(), AtomicOrdering::Monotonic))
     return ModRefInfo::ModRef;
 
+  // For Monotonic and unordered loads, we only need to be more conservative
+  // when the locations are MustAlias to prevent unsafe reordering of accesses
+  // to the same memory. For MayAlias, we can treat it as a normal read.
+  if (L->isAtomic()) {
+    if (Loc.Ptr &&
+        alias(MemoryLocation::get(L), Loc, AAQI, L) == AliasResult::MustAlias)
----------------
nikic wrote:

Basically, what I'd like to see is that the `return ModRefInfo::Ref;` below gets replaced with `return IsStrongerThanUnordered ? ModRefInfo::ModRef : ModRefInfo::Ref`. The rest of the code shouldn't need to change.

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


More information about the llvm-commits mailing list