[llvm] [MemCpyOpt] Calculate the offset value to forward `memcpy` (PR #87190)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 1 07:47:23 PDT 2024
================
@@ -1152,11 +1188,12 @@ bool MemCpyOptPass::processMemCpyMemCpyDependence(MemCpyInst *M,
//
// TODO: If the code between M and MDep is transparent to the destination "c",
// then we could still perform the xform by moving M up to the first memcpy.
- // TODO: It would be sufficient to check the MDep source up to the memcpy
- // size of M, rather than MDep.
- if (writtenBetween(MSSA, BAA, MemoryLocation::getForSource(MDep),
- MSSA->getMemoryAccess(MDep), MSSA->getMemoryAccess(M)))
+ if (writtenBetween(MSSA, BAA, MCopyLoc, MSSA->getMemoryAccess(MDep),
+ MSSA->getMemoryAccess(M))) {
+ if (MForwardOffset > 0 && CopySource->use_empty())
+ cast<Instruction>(CopySource)->eraseFromParent();
----------------
dtcxzyw wrote:
Should we remove the temporary GEP here?
```
bool UseMemMove = false;
if (isModSet(BAA.getModRefInfo(M, MemoryLocation::getForSource(MDep)))) {
// Don't convert llvm.memcpy.inline into memmove because memmove can be
// lowered as a call, and that is not allowed for llvm.memcpy.inline (and
// there is no inline version of llvm.memmove)
if (isa<MemCpyInlineInst>(M))
return false; --> Remove CopySource if unused
UseMemMove = true;
}
```
https://github.com/llvm/llvm-project/pull/87190
More information about the llvm-commits
mailing list