Skip to content

MemCpyOpt: replace an AA query with MSSA query (NFC) #108535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,19 +647,18 @@ bool MemCpyOptPass::processStoreOfLoad(StoreInst *SI, LoadInst *LI,
(EnableMemCpyOptWithoutLibcalls ||
(TLI->has(LibFunc_memcpy) && TLI->has(LibFunc_memmove)))) {
MemoryLocation LoadLoc = MemoryLocation::get(LI);

// We use alias analysis to check if an instruction may store to
// the memory we load from in between the load and the store. If
// such an instruction is found, we try to promote there instead
// of at the store position.
// TODO: Can use MSSA for this.
Instruction *P = SI;
for (auto &I : make_range(++LI->getIterator(), SI->getIterator())) {
if (isModSet(AA->getModRefInfo(&I, LoadLoc))) {
P = &I;
break;
}
}
MemoryUseOrDef *LoadAccess = MSSA->getMemoryAccess(LI),
*StoreAccess = MSSA->getMemoryAccess(SI);

// We use MSSA to check if an instruction may store to the memory we load
// from in between the load and the store. If such an instruction is found,
// we try to promote there instead of at the store position.
BatchAAResults BAA(*AA);
auto *Clobber =
cast<MemoryUseOrDef>(MSSA->getWalker()->getClobberingMemoryAccess(
StoreAccess->getDefiningAccess(), LoadLoc, BAA));
Instruction *P =
MSSA->dominates(LoadAccess, Clobber) ? Clobber->getMemoryInst() : SI;

// If we found an instruction that may write to the loaded memory,
// we can try to promote at this position instead of the store
Expand Down
Loading