aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorRamkumar Ramachandra <ramkumar.ramachandra@codasip.com>2024-09-24 11:18:37 +0100
committerGitHub <noreply@github.com>2024-09-24 11:18:37 +0100
commitf664d313cd63893d7a4a496fdf0de988323b6b09 (patch)
tree02e8c31a3c7f2de30ce7114557a1edf34f5c34ad /llvm/lib
parentfc661df41a206779a9323fb9dd49038c44084d5e (diff)
downloadllvm-f664d313cd63893d7a4a496fdf0de988323b6b09.zip
llvm-f664d313cd63893d7a4a496fdf0de988323b6b09.tar.gz
llvm-f664d313cd63893d7a4a496fdf0de988323b6b09.tar.bz2
MemCpyOpt: replace an AA query with MSSA query (NFC) (#108535)
Fix a long-standing TODO.
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index 1d67773..2f88b19 100644
--- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -638,6 +638,7 @@ bool MemCpyOptPass::processStoreOfLoad(StoreInst *SI, LoadInst *LI,
if (!LI->isSimple() || !LI->hasOneUse() || LI->getParent() != SI->getParent())
return false;
+ BatchAAResults BAA(*AA);
auto *T = LI->getType();
// Don't introduce calls to memcpy/memmove intrinsics out of thin air if
// the corresponding libcalls are not available.
@@ -647,19 +648,17 @@ 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.
+ auto *Clobber = MSSA->getWalker()->getClobberingMemoryAccess(
+ StoreAccess->getDefiningAccess(), LoadLoc, BAA);
+ Instruction *P = MSSA->dominates(LoadAccess, Clobber)
+ ? cast<MemoryUseOrDef>(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
@@ -707,7 +706,6 @@ bool MemCpyOptPass::processStoreOfLoad(StoreInst *SI, LoadInst *LI,
// Detect cases where we're performing call slot forwarding, but
// happen to be using a load-store pair to implement it, rather than
// a memcpy.
- BatchAAResults BAA(*AA);
auto GetCall = [&]() -> CallInst * {
// We defer this expensive clobber walk until the cheap checks
// have been done on the source inside performCallSlotOptzn.