[llvm] Reapply "[MemCpyOpt] support offset slices for performStackMoveOptzn and processMemCpy", with bug fixed (PR #180002)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 10 06:22:55 PST 2026


================
@@ -1662,8 +1684,16 @@ bool MemCpyOptPass::performStackMoveOptzn(Instruction *Load, Instruction *Store,
 
   // Check that, from after the Load to the end of the BB,
   //   - if the dest has any Mod, src has no Ref, and
-  //   - if the dest has any Ref, src has no Mod except full-sized lifetimes.
-  MemoryLocation SrcLoc(SrcAlloca, LocationSize::precise(Size));
+  //   - if the dest has any Ref, src has no Mod except full-sized lifetimes
+  // Where:
+  //   - src is defined as the memory from max(SrcAlloca, SrcPtr minus
+  //     dest_offset) to min(dest_size, SrcSize minus SrcOffset)
+  //   - dest_offset and dest_size could be computed by DestModRefCallback
+  //     to be the bounds of the first and last mod region, and which is at
+  //     least as large as DestOffset to DestSize, and at most as large as
+  //     SrcAlloca to SrcSize.
----------------
nikic wrote:

The important part here is the preceding bullet point, which can be stated in terms of DestOffset and DestSize, without the entirely unnecessary suggestion of "well actually, we could also perform additional inference to refine these values further".

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


More information about the llvm-commits mailing list