[llvm] [MemCpyOpt] Drop dead `memmove` calls on `memset`'d source data (PR #101930)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 29 13:38:23 PST 2024
================
@@ -1841,12 +1842,77 @@ 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 *MemMoveSourceOp = M->getSource();
+ auto *Source = dyn_cast<GEPOperator>(MemMoveSourceOp);
+ if (!Source)
+ return false;
+
+ APInt Offset(DL.getIndexTypeSizeInBits(Source->getType()), 0);
+ LocationSize MemMoveLocSize = SourceLoc.Size;
+ if (Source->getPointerOperand() != M->getDest() ||
+ !MemMoveLocSize.hasValue() ||
+ !Source->accumulateConstantOffset(DL, Offset) || Offset.isNegative()) {
+ return false;
+ }
+
+ uint64_t MemMoveSize = MemMoveLocSize.getValue();
+ LocationSize TotalSize =
+ LocationSize::precise(Offset.getZExtValue() + MemMoveSize);
+ MemoryLocation CombinedSourceLoc(MemMoveSourceOp, TotalSize);
----------------
nikic wrote:
Unused variable.
https://github.com/llvm/llvm-project/pull/101930
More information about the llvm-commits
mailing list