[llvm] [MemCpyOpt] No need to create `memcpy(a <- a)` (PR #98321)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 10 07:35:23 PDT 2024


================
@@ -1161,6 +1161,14 @@ bool MemCpyOptPass::processMemCpyMemCpyDependence(MemCpyInst *M,
                      MSSA->getMemoryAccess(MDep), MSSA->getMemoryAccess(M)))
     return false;
 
+  // No need to create `memcpy(a <- a)`.
+  if (BAA.isMustAlias(M->getDest(), MDep->getRawSource())) {
----------------
dtcxzyw wrote:

```suggestion
  if (!M->isVolatile() && BAA.isMustAlias(M->getDest(), MDep->getRawSource())) {
```
> The optimizers must not change the number of volatile operations or change their order of execution relative to other volatile operations.

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


More information about the llvm-commits mailing list