[llvm] [MemCpyOpt] allow more memcpy-to-memcpy optimization (PR #150792)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 14 13:02:03 PST 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index 1348cca6d..af85bcdc6 100644
--- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -1638,10 +1638,10 @@ bool MemCpyOptPass::performStackMoveOptzn(Instruction *Load, Instruction *Store,
     return false;
 
   // Check that copy is full with dest size, either because it wrote every byte,
-  // or it was fresh. The store itself was ignored earlier, but might be in a loop,
-  // so it could (in rare cases) observe that earlier store which needs to be checked for now.
-  // For example, a source language might emit code matching that pattern for a
-  // simple array reverse with a struct element type:
+  // or it was fresh. The store itself was ignored earlier, but might be in a
+  // loop, so it could (in rare cases) observe that earlier store which needs to
+  // be checked for now. For example, a source language might emit code matching
+  // that pattern for a simple array reverse with a struct element type:
   //   for (i = 0; i < size; i++) dest[size - i - 1] = src[i];
   if (Size != *DestSize) {
     // Similar analysis to overreadUndefContents
@@ -1656,10 +1656,12 @@ bool MemCpyOptPass::performStackMoveOptzn(Instruction *Load, Instruction *Store,
     } else {
       llvm_unreachable("performStackMoveOptzn must have a known store kind");
     }
-    // If offset and size are constant, then this overwrote the same bytes every time anyways.
+    // If offset and size are constant, then this overwrote the same bytes every
+    // time anyways.
     if (!Ptr->getPointerOffsetFrom(DestAlloca, DL)) {
       // Otherwise, if the other bytes are not known-undef, then also need to
-      // consider whether they could have been defined by this same store in a loop.
+      // consider whether they could have been defined by this same store in a
+      // loop.
       MemoryUseOrDef *MemAccess = MSSA->getMemoryAccess(Store);
       MemoryAccess *Clobber = MSSA->getWalker()->getClobberingMemoryAccess(
           MemAccess->getDefiningAccess(), Loc, BAA);

``````````

</details>


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


More information about the llvm-commits mailing list