[llvm] MemCpyOpt: replace an AA query with MSSA query (PR #108535)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 14 00:53:34 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(
+            StoreAccess, LoadLoc, BAA));
----------------
nikic wrote:

```suggestion
            StoreAccess->getDefinintAccess(), LoadLoc, BAA));
```
So you don't get back the store itself.

https://github.com/llvm/llvm-project/pull/108535


More information about the llvm-commits mailing list