[llvm] [AA] Improve precision for monotonic atomic load/store operations (PR #158169)
Jin Huang via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 15 09:16:04 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 atomic loads, if the locations are not NoAlias,
+ // we must be conservative and return ModRef to prevent unsafe reordering of
+ // accesses to the same memory.
+ if (L->isAtomic()){
+ if (Loc.Ptr &&
+ alias(MemoryLocation::get(L), Loc, AAQI, L) != AliasResult::NoAlias)
+ return ModRefInfo::ModRef;
+ }
----------------
jinhuang1102 wrote:
I see. You means that treat `unordered` like the non-atomic load and add the following code:
```c++
if (isStrongerThanUnordered(L->getOrdering()))
return ModRefInfo::ModRef;
```
After the `AliasResult AR` check:
```
if (Loc.Ptr) {
AliasResult AR = alias(MemoryLocation::get(L), Loc, AAQI, L);
if (AR == AliasResult::NoAlias)
return ModRefInfo::NoModRef;
}
```
Am I right?
https://github.com/llvm/llvm-project/pull/158169
More information about the llvm-commits
mailing list