[llvm] [MemCpyOpt] allow some undef contents overread in processMemCpyMemCpyDependence (PR #143745)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 12 01:46:12 PDT 2025


================
@@ -1152,9 +1169,13 @@ bool MemCpyOptPass::processMemCpyMemCpyDependence(MemCpyInst *M,
       eraseInstruction(NewCopySource);
   });
   MaybeAlign CopySourceAlign = MDep->getSourceAlign();
-  // We just need to calculate the actual size of the copy.
-  auto MCopyLoc = MemoryLocation::getForSource(MDep).getWithNewSize(
-      MemoryLocation::getForSource(M).Size);
+  auto MCopyLoc = MemoryLocation::getForSource(MDep);
+  // Truncate the size of the MDep access to just the bytes read
+  if (MDep->getLength() != CopyLength) {
+    auto ConstLength = cast<ConstantInt>(CopyLength);
----------------
nikic wrote:

```suggestion
    auto *ConstLength = cast<ConstantInt>(CopyLength);
```

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


More information about the llvm-commits mailing list