[llvm] [MemCpyOpt] Drop dead `memmove` calls on `memset`'d source data (PR #101930)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 29 08:06:40 PST 2024
================
@@ -1843,12 +1844,68 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
return false;
}
+/// Memmove calls with overlapping src/dest buffers that come after a memset may
+/// be removed.
+bool MemCpyOptPass::isMemMoveMemSetDependency(MemMoveInst *M) {
+ const auto &DL = M->getDataLayout();
+ MemoryUseOrDef *MemMoveAccess = MSSA->getMemoryAccess(M);
+ if (!MemMoveAccess)
+ return false;
+
+ // The memmove is of form memmove(x, x + A, B).
+ MemoryLocation SourceLoc = MemoryLocation::getForSource(M);
+ auto *Source = dyn_cast<GetElementPtrInst>(M->getSource());
+ if (!Source)
+ return false;
+ APInt Offset(DL.getIndexTypeSizeInBits(Source->getType()), 0);
+ auto MemMoveSize = SourceLoc.Size;
+ if (!Source->accumulateConstantOffset(DL, Offset) || Offset.isNegative() ||
+ Source->getPointerOperand() != M->getDest() || !MemMoveSize.hasValue())
----------------
antoniofrighetto wrote:
Should have done earlier.
https://github.com/llvm/llvm-project/pull/101930
More information about the llvm-commits
mailing list