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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 23 05:29:19 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(
----------------
nikic wrote:

```llvm
define void @test(ptr %a, ptr %b) {
  br label %loop 

loop: 
  %v = load { i64, i64 }, ptr %a
  store { i64, i64 } %v, ptr %b 
  br label %loop 
} 
```
should be enough to reproduce the assertion failure.

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


More information about the llvm-commits mailing list