[llvm] [memcpyopt] fix incorrect handling of lifetime markers (PR #143782)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 11 13:47:09 PDT 2025
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 HEAD~1 HEAD --extensions cpp -- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
``````````
</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 fc439be40..877600034 100644
--- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -1367,8 +1367,9 @@ bool MemCpyOptPass::processMemSetMemCpyDependence(MemCpyInst *MemCpy,
/// Determine whether the pointer V had only undefined content (due to Def) up
/// to the given Size, either because it was freshly alloca'd or started its
/// lifetime by walking the MSSA graph.
-static bool hadUndefContentsBefore(MemorySSA *MSSA, BatchAAResults &BAA, Value *V,
- MemoryAccess *Clobber, MemoryLocation Loc, Value *Size) {
+static bool hadUndefContentsBefore(MemorySSA *MSSA, BatchAAResults &BAA,
+ Value *V, MemoryAccess *Clobber,
+ MemoryLocation Loc, Value *Size) {
while (1) {
Clobber = MSSA->getWalker()->getClobberingMemoryAccess(Clobber, Loc, BAA);
MemoryDef *Def = dyn_cast<MemoryDef>(Clobber);
@@ -1416,14 +1417,16 @@ static bool hadUndefContentsBefore(MemorySSA *MSSA, BatchAAResults &BAA, Value *
// If the memcpy is larger than the previous, but the memory was undef prior to
// that, we can just ignore the tail. Technically we're only interested in the
// bytes from 0..MemSrcOffset and MemSrcLength+MemSrcOffset..CopySize here, but
-// as we can't easily represent this location (hadUndefContentsBefore uses mustAlias
-// which cannot deal with offsets), we use the full 0..CopySize range.
+// as we can't easily represent this location (hadUndefContentsBefore uses
+// mustAlias which cannot deal with offsets), we use the full 0..CopySize range.
static bool overreadUndefContents(MemorySSA *MSSA, MemCpyInst *MemCpy,
MemIntrinsic *MemSrc, BatchAAResults &BAA) {
Value *CopySize = MemCpy->getLength();
MemoryLocation LoadLoc = MemoryLocation::getForSource(MemCpy);
- MemoryAccess *MemSrcAccess = MSSA->getMemoryAccess(MemSrc)->getDefiningAccess();
- if (hadUndefContentsBefore(MSSA, BAA, MemCpy->getSource(), MemSrcAccess, LoadLoc, CopySize))
+ MemoryAccess *MemSrcAccess =
+ MSSA->getMemoryAccess(MemSrc)->getDefiningAccess();
+ if (hadUndefContentsBefore(MSSA, BAA, MemCpy->getSource(), MemSrcAccess,
+ LoadLoc, CopySize))
return true;
return false;
}
@@ -1791,8 +1794,8 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
return true;
MemoryLocation SrcLoc = MemoryLocation::getForSource(M);
- MemoryAccess *SrcClobber = MSSA->getWalker()->getClobberingMemoryAccess(
- AnyClobber, SrcLoc, BAA);
+ MemoryAccess *SrcClobber =
+ MSSA->getWalker()->getClobberingMemoryAccess(AnyClobber, SrcLoc, BAA);
// There are five possible optimizations we can do for memcpy:
// a) memcpy-memcpy xform which exposes redundance for DSE.
@@ -1832,7 +1835,8 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
}
}
- if (hadUndefContentsBefore(MSSA, BAA, M->getSource(), AnyClobber, SrcLoc, M->getLength())) {
+ if (hadUndefContentsBefore(MSSA, BAA, M->getSource(), AnyClobber, SrcLoc,
+ M->getLength())) {
LLVM_DEBUG(dbgs() << "Removed memcpy from undef\n");
eraseInstruction(M);
++NumMemCpyInstr;
``````````
</details>
https://github.com/llvm/llvm-project/pull/143782
More information about the llvm-commits
mailing list