[llvm] [memcpyopt] handle memcpy from memset in more cases (PR #140954)

Jameson Nash via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 9 08:22:54 PDT 2025


================
@@ -1418,51 +1437,52 @@ static bool hasUndefContents(MemorySSA *MSSA, BatchAAResults &AA, Value *V,
 bool MemCpyOptPass::performMemCpyToMemSetOptzn(MemCpyInst *MemCpy,
                                                MemSetInst *MemSet,
                                                BatchAAResults &BAA) {
-  // Make sure that memcpy(..., memset(...), ...), that is we are memsetting and
-  // memcpying from the same address. Otherwise it is hard to reason about.
-  if (!BAA.isMustAlias(MemSet->getRawDest(), MemCpy->getRawSource()))
-    return false;
-
   Value *MemSetSize = MemSet->getLength();
   Value *CopySize = MemCpy->getLength();
 
-  if (MemSetSize != CopySize) {
-    // Make sure the memcpy doesn't read any more than what the memset wrote.
-    // Don't worry about sizes larger than i64.
+  int64_t MOffset = 0;
----------------
vtjnash wrote:

This would be a deviation from the original copy of this code (in processMemCpyMemCpyDependence), while the purpose of the PR was to reduce the deviation between those two methods

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


More information about the llvm-commits mailing list