[llvm] [AMDGPU] Employ MemorySSA when rewriting out arguments (NFCI) (PR #207922)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 04:13:00 PDT 2026
================
@@ -170,6 +174,46 @@ bool AMDGPURewriteOutArguments::doInitialization(Module &M) {
return false;
}
+static StoreInst *findStoreForOutArgument(BasicBlock *BB, Argument *OutArg,
+ MemorySSA &MSSA, AAResults &AA) {
+ MemoryLocation ArgLoc = MemoryLocation::getBeforeOrAfter(OutArg);
+ if (const auto *Accesses = MSSA.getBlockAccesses(BB)) {
+ for (const MemoryAccess &Access : reverse(*Accesses)) {
+ const auto *UseOrDef = dyn_cast<MemoryUseOrDef>(&Access);
+ if (!UseOrDef)
+ continue;
+
+ Instruction *I = UseOrDef->getMemoryInst();
+
+ // Return the must-alias store to the out argument.
+ if (auto *Store = dyn_cast<StoreInst>(I))
+ if (Store->getPointerOperand() == OutArg)
+ return Store;
+
+ if (auto *FI = dyn_cast<FenceInst>(I))
+ if (FI->getOrdering() == AtomicOrdering::Release)
+ continue;
+
+ if (auto *LI = dyn_cast<LoadInst>(I)) {
+ if (LI->isAtomic()) {
+ // May-alias reads with monotonic ordering are ignored.
+ if (isStrongerThan(LI->getOrdering(), AtomicOrdering::Monotonic))
+ return nullptr;
+ continue;
+ }
+ }
+
+ // Any other memory access that writes the location prevents the
+ // rewrite.
+ // FIXME: should handle aliasing reads too.
+ if (isModSet(AA.getModRefInfo(I, ArgLoc)))
----------------
antoniofrighetto wrote:
Sure, thanks.
https://github.com/llvm/llvm-project/pull/207922
More information about the llvm-commits
mailing list