[llvm] MemCpyOpt: replace an AA query with MSSA query (NFC) (PR #108535)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 23 04:02:20 PDT 2024
================
@@ -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(
----------------
artagnon wrote:
> It would be good to add a test where we get a MemoryPhi result.
I _think_ it's impossible to write a suitable testcase, as we have:
```cpp
bool MemCpyOptPass::processStoreOfLoad(StoreInst *SI, LoadInst *LI,
const DataLayout &DL,
BasicBlock::iterator &BBI) {
if (!LI->isSimple() || !LI->hasOneUse() || LI->getParent() != SI->getParent())
return false;
```
Here, `LI->getParent() == SI->getParent()` for the code to be executed. This doesn't leave room for intervening phis.
https://github.com/llvm/llvm-project/pull/108535
More information about the llvm-commits
mailing list