[llvm] [MemCpyOpt] allow more memcpy-to-memcpy optimization (PR #150792)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 14 11:57:04 PST 2026


================
@@ -1508,21 +1532,33 @@ bool MemCpyOptPass::performStackMoveOptzn(Instruction *Load, Instruction *Store,
     return false;
   }
 
-  // Check that copy is full with static size.
-  const DataLayout &DL = DestAlloca->getDataLayout();
-  std::optional<TypeSize> SrcSize = SrcAlloca->getAllocationSize(DL);
-  if (!SrcSize || Size != *SrcSize) {
-    LLVM_DEBUG(dbgs() << "Stack Move: Source alloca size mismatch\n");
+  if (SrcAlloca->isUsedWithInAlloca() || DestAlloca->isUsedWithInAlloca())
----------------
nikic wrote:

>From a cursory look it seems like we fail to document this in LangRef right now, but the reason this works is that static allocas are never affected by stacksave/stackrestore, regardless of how things are ordered in the entry block.

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


More information about the llvm-commits mailing list