[llvm] [IR] Add Instruction::maySynchronize() method (NFC) (PR #196052)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Wed May 6 07:10:37 PDT 2026
================
@@ -1933,46 +1933,15 @@ static bool InstrBreaksNoFree(Instruction &I, const SCCNodeSet &SCCNodes) {
return true;
}
-// Return true if this is an atomic which has an ordering stronger than
-// unordered. Note that this is different than the predicate we use in
-// Attributor. Here we chose to be conservative and consider monotonic
-// operations potentially synchronizing. We generally don't do much with
-// monotonic operations, so this is simply risk reduction.
-static bool isOrderedAtomic(Instruction *I) {
- if (!I->isAtomic())
- return false;
-
- if (auto *FI = dyn_cast<FenceInst>(I))
- // All legal orderings for fence are stronger than monotonic.
- return FI->getSyncScopeID() != SyncScope::SingleThread;
- else if (isa<AtomicCmpXchgInst>(I) || isa<AtomicRMWInst>(I))
- return true;
- else if (auto *SI = dyn_cast<StoreInst>(I))
- return !SI->isUnordered();
- else if (auto *LI = dyn_cast<LoadInst>(I))
- return !LI->isUnordered();
- else {
- llvm_unreachable("unknown atomic instruction?");
- }
-}
-
static bool InstrBreaksNoSync(Instruction &I, const SCCNodeSet &SCCNodes) {
- // An ordered atomic may synchronize. (See comment about on monotonic.)
- if (isOrderedAtomic(&I))
- return true;
-
- auto *CB = dyn_cast<CallBase>(&I);
- if (!CB)
- // Non call site cases covered by the two checks above
+ if (!I.maySynchronize())
return false;
- if (CB->hasFnAttr(Attribute::NoSync))
- return false;
-
- // Speculatively assume in SCC.
- if (Function *Callee = CB->getCalledFunction())
- if (SCCNodes.contains(Callee))
- return false;
+ // Speculatively assume nosync in SCC.
----------------
antoniofrighetto wrote:
While at it, could the previous comment use an update? (The intent would be to remind we're trying to find a reason to disqualify...)
```suggestion
// Optimistically assume calls within the SCC are nosync: if nothing else
// in the SCC synchronizes, the assumption holds.
```
https://github.com/llvm/llvm-project/pull/196052
More information about the llvm-commits
mailing list