[llvm] [MemCpyOpt] support offset slices for performStackMoveOptzn and processMemCpy (PR #176436)

Jameson Nash via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 19 09:28:33 PST 2026


https://github.com/vtjnash updated https://github.com/llvm/llvm-project/pull/176436

>From 6c8676ee8cdd5cb21a0fa402d67f6870b00ac3e5 Mon Sep 17 00:00:00 2001
From: Jameson Nash <vtjnash at gmail.com>
Date: Wed, 14 Jan 2026 22:11:33 +0000
Subject: [PATCH] [MemCpyOpt] support offset slices for performStackMoveOptzn
 and processMemCpy

In particular, support offset of src, since offset of dest will be a
followup change when dest is allowed to be not full-sized with copy.
---
 .../llvm/Transforms/Scalar/MemCpyOptimizer.h  |  13 +-
 .../lib/Transforms/Scalar/MemCpyOptimizer.cpp |  78 +++---
 .../Transforms/MemCpyOpt/stack-move-offset.ll | 238 ++++++++++++++++++
 3 files changed, 295 insertions(+), 34 deletions(-)
 create mode 100644 llvm/test/Transforms/MemCpyOpt/stack-move-offset.ll

diff --git a/llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h b/llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h
index 496d2958fc2d0..b87ea0b9d243f 100644
--- a/llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h
+++ b/llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h
@@ -16,6 +16,7 @@
 
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/PassManager.h"
+#include "llvm/Support/Compiler.h"
 
 namespace llvm {
 
@@ -54,12 +55,12 @@ class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
 public:
   MemCpyOptPass() = default;
 
-  PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+  LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
 
   // Glue for the old PM.
-  bool runImpl(Function &F, TargetLibraryInfo *TLI, AAResults *AA,
-               AssumptionCache *AC, DominatorTree *DT, PostDominatorTree *PDT,
-               MemorySSA *MSSA);
+  LLVM_ABI bool runImpl(Function &F, TargetLibraryInfo *TLI, AAResults *AA,
+                        AssumptionCache *AC, DominatorTree *DT,
+                        PostDominatorTree *PDT, MemorySSA *MSSA);
 
 private:
   // Helper functions
@@ -85,8 +86,8 @@ class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
                                     Value *ByteVal);
   bool moveUp(StoreInst *SI, Instruction *P, const LoadInst *LI);
   bool performStackMoveOptzn(Instruction *Load, Instruction *Store,
-                             AllocaInst *DestAlloca, AllocaInst *SrcAlloca,
-                             TypeSize Size, BatchAAResults &BAA);
+                             Value *DestPtr, Value *SrcPtr, TypeSize Size,
+                             BatchAAResults &BAA);
   bool isMemMoveMemSetDependency(MemMoveInst *M);
 
   void eraseInstruction(Instruction *I);
diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index 5de3dfa148314..d8d784f2ff774 100644
--- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -726,18 +726,15 @@ bool MemCpyOptPass::processStoreOfLoad(StoreInst *SI, LoadInst *LI,
   // If this is a load-store pair from a stack slot to a stack slot, we
   // might be able to perform the stack-move optimization just as we do for
   // memcpys from an alloca to an alloca.
-  if (auto *DestAlloca = dyn_cast<AllocaInst>(SI->getPointerOperand())) {
-    if (auto *SrcAlloca = dyn_cast<AllocaInst>(LI->getPointerOperand())) {
-      if (performStackMoveOptzn(LI, SI, DestAlloca, SrcAlloca,
-                                DL.getTypeStoreSize(T), BAA)) {
-        // Avoid invalidating the iterator.
-        BBI = SI->getNextNode()->getIterator();
-        eraseInstruction(SI);
-        eraseInstruction(LI);
-        ++NumMemCpyInstr;
-        return true;
-      }
-    }
+  if (performStackMoveOptzn(LI, SI, SI->getPointerOperand(),
+                            LI->getPointerOperand(), DL.getTypeStoreSize(T),
+                            BAA)) {
+    // Avoid invalidating the iterator.
+    BBI = SI->getNextNode()->getIterator();
+    eraseInstruction(SI);
+    eraseInstruction(LI);
+    ++NumMemCpyInstr;
+    return true;
   }
 
   return false;
@@ -1497,20 +1494,47 @@ bool MemCpyOptPass::performMemCpyToMemSetOptzn(MemCpyInst *MemCpy,
 // transformation only because we restrict the scope of this optimization to
 // allocas that aren't captured.
 bool MemCpyOptPass::performStackMoveOptzn(Instruction *Load, Instruction *Store,
-                                          AllocaInst *DestAlloca,
-                                          AllocaInst *SrcAlloca, TypeSize Size,
-                                          BatchAAResults &BAA) {
+                                          Value *DestPtr, Value *SrcPtr,
+                                          TypeSize Size, BatchAAResults &BAA) {
   LLVM_DEBUG(dbgs() << "Stack Move: Attempting to optimize:\n"
                     << *Store << "\n");
 
+  AllocaInst *DestAlloca = dyn_cast<AllocaInst>(getUnderlyingObject(DestPtr));
+  if (!DestAlloca)
+    return false;
+
+  AllocaInst *SrcAlloca = dyn_cast<AllocaInst>(getUnderlyingObject(SrcPtr));
+  if (!SrcAlloca)
+    return false;
+
+  // Explicitly don't handle degenerate case of a partial copy within one
+  // alloca. It would always fail the dominator check later anyways, and
+  // possibly the modref checks also.
+  if (SrcAlloca == DestAlloca)
+    return false;
+
   // Make sure the two allocas are in the same address space.
   if (SrcAlloca->getAddressSpace() != DestAlloca->getAddressSpace()) {
     LLVM_DEBUG(dbgs() << "Stack Move: Address space mismatch\n");
     return false;
   }
 
+  if (!SrcAlloca->isStaticAlloca() || !DestAlloca->isStaticAlloca())
+    return false;
+
   // Check that copy is full with static size.
   const DataLayout &DL = DestAlloca->getDataLayout();
+
+  auto DestOffset = DestPtr->getPointerOffsetFrom(DestAlloca, DL);
+  if (!DestOffset)
+    return false;
+
+  auto SrcOffset = SrcPtr->getPointerOffsetFrom(SrcAlloca, DL);
+  if (!SrcOffset || *SrcOffset < *DestOffset || *SrcOffset < 0)
+    return false;
+  // Offset difference must preserve dest alloca's alignment.
+  if ((*SrcOffset - *DestOffset) % DestAlloca->getAlign().value() != 0)
+    return false;
   std::optional<TypeSize> SrcSize = SrcAlloca->getAllocationSize(DL);
   std::optional<TypeSize> DestSize = DestAlloca->getAllocationSize(DL);
   if (!SrcSize || !DestSize)
@@ -1518,14 +1542,12 @@ bool MemCpyOptPass::performStackMoveOptzn(Instruction *Load, Instruction *Store,
   if (*SrcSize != *DestSize)
     if (!SrcSize->isFixed() || !DestSize->isFixed())
       return false;
-  if (Size != *DestSize) {
+  // Check that copy covers entirety of dest alloca.
+  if (Size != *DestSize || *DestOffset != 0) {
     LLVM_DEBUG(dbgs() << "Stack Move: Destination alloca size mismatch\n");
     return false;
   }
 
-  if (!SrcAlloca->isStaticAlloca() || !DestAlloca->isStaticAlloca())
-    return false;
-
   // Check if it will be legal to combine allocas without breaking dominator.
   bool MoveSrc = !DT->dominates(SrcAlloca, DestAlloca);
   if (MoveSrc) {
@@ -1689,7 +1711,13 @@ bool MemCpyOptPass::performStackMoveOptzn(Instruction *Load, Instruction *Store,
   }
 
   // Merge the two allocas.
-  DestAlloca->replaceAllUsesWith(SrcAlloca);
+  Value *NewDestPtr = SrcAlloca;
+  if (*SrcOffset != *DestOffset) {
+    IRBuilder<> Builder(DestAlloca);
+    NewDestPtr = Builder.CreateInBoundsPtrAdd(
+        SrcAlloca, Builder.getInt64(*SrcOffset - *DestOffset));
+  }
+  DestAlloca->replaceAllUsesWith(NewDestPtr);
   eraseInstruction(DestAlloca);
 
   // Drop metadata on the source alloca.
@@ -1760,7 +1788,7 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
     return false;
 
   // If copying from a constant, try to turn the memcpy into a memset.
-  if (auto *GV = dyn_cast<GlobalVariable>(M->getSource()))
+  if (auto *GV = dyn_cast<GlobalVariable>(getUnderlyingObject(M->getSource())))
     if (GV->isConstant() && GV->hasDefinitiveInitializer())
       if (Value *ByteVal = isBytewiseValue(GV->getInitializer(),
                                            M->getDataLayout())) {
@@ -1846,16 +1874,10 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
   // If the transfer is from a stack slot to a stack slot, then we may be able
   // to perform the stack-move optimization. See the comments in
   // performStackMoveOptzn() for more details.
-  auto *DestAlloca = dyn_cast<AllocaInst>(M->getDest());
-  if (!DestAlloca)
-    return false;
-  auto *SrcAlloca = dyn_cast<AllocaInst>(M->getSource());
-  if (!SrcAlloca)
-    return false;
   ConstantInt *Len = dyn_cast<ConstantInt>(M->getLength());
   if (Len == nullptr)
     return false;
-  if (performStackMoveOptzn(M, M, DestAlloca, SrcAlloca,
+  if (performStackMoveOptzn(M, M, M->getDest(), M->getSource(),
                             TypeSize::getFixed(Len->getZExtValue()), BAA)) {
     // Avoid invalidating the iterator.
     BBI = M->getNextNode()->getIterator();
diff --git a/llvm/test/Transforms/MemCpyOpt/stack-move-offset.ll b/llvm/test/Transforms/MemCpyOpt/stack-move-offset.ll
new file mode 100644
index 0000000000000..fdf5e838b20e5
--- /dev/null
+++ b/llvm/test/Transforms/MemCpyOpt/stack-move-offset.ll
@@ -0,0 +1,238 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; RUN: opt < %s -passes=memcpyopt -verify-memoryssa -S | FileCheck %s
+
+; Test that stack-move optimization works when src is a GEP into an alloca.
+; For the optimization to trigger:
+;   - The copy must cover the entire dest alloca (Size == DestSize, DestOffset == 0)
+;   - SrcOffset must be a multiple of DestAlloca's alignment
+;   - SrcOffset must be non-negative
+
+declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg)
+declare void @llvm.lifetime.start.p0(ptr nocapture)
+declare void @llvm.lifetime.end.p0(ptr nocapture)
+
+declare void @use_nocapture(ptr nocapture)
+
+; Basic test: memcpy from GEP(src) to dest alloca
+; src = [16 x i8], dest = [8 x i8] align 8, copy 8 bytes
+; SrcOffset(8) is a multiple of DestAlign(8), so optimization applies.
+; After optimization: dest uses become src+8
+define void @memcpy_src_gep_to_dest_alloca() {
+; CHECK-LABEL: define void @memcpy_src_gep_to_dest_alloca() {
+; CHECK-NEXT:    [[SRC:%.*]] = alloca [16 x i8], align 8
+; CHECK-NEXT:    [[SRC_GEP:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i64 8
+; CHECK-NEXT:    [[SRC_GEP1:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i64 8
+; CHECK-NEXT:    store i64 42, ptr [[SRC_GEP1]], align 4
+; CHECK-NEXT:    call void @use_nocapture(ptr captures(none) [[SRC_GEP1]])
+; CHECK-NEXT:    call void @use_nocapture(ptr captures(none) [[SRC_GEP]])
+; CHECK-NEXT:    ret void
+;
+  %src = alloca [16 x i8], align 4
+  %dest = alloca [8 x i8], align 8
+  call void @llvm.lifetime.start.p0(ptr %src)
+  call void @llvm.lifetime.start.p0(ptr %dest)
+  %src.gep = getelementptr inbounds i8, ptr %src, i64 8
+  store i64 42, ptr %src.gep
+  call void @use_nocapture(ptr nocapture %src.gep)
+
+  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %dest, ptr align 8 %src.gep, i64 8, i1 false)
+
+  call void @use_nocapture(ptr nocapture %dest)
+
+  call void @llvm.lifetime.end.p0(ptr %src)
+  call void @llvm.lifetime.end.p0(ptr %dest)
+  ret void
+}
+
+; Test: memcpy from GEP(src) to dest alloca with different offset
+; src = [12 x i8], dest = [8 x i8] align 4, copy 8 bytes from src+4
+; SrcOffset(4) is a multiple of DestAlign(4), so optimization applies.
+; After optimization: dest uses become src+4
+define void @memcpy_src_gep_offset4_to_dest_alloca() {
+; CHECK-LABEL: define void @memcpy_src_gep_offset4_to_dest_alloca() {
+; CHECK-NEXT:    [[SRC:%.*]] = alloca [12 x i8], align 4
+; CHECK-NEXT:    [[SRC_GEP:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i64 4
+; CHECK-NEXT:    [[SRC_GEP1:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i64 4
+; CHECK-NEXT:    store i64 42, ptr [[SRC_GEP1]], align 4
+; CHECK-NEXT:    call void @use_nocapture(ptr captures(none) [[SRC_GEP1]])
+; CHECK-NEXT:    call void @use_nocapture(ptr captures(none) [[SRC_GEP]])
+; CHECK-NEXT:    ret void
+;
+  %src = alloca [12 x i8], align 4
+  %dest = alloca [8 x i8], align 4
+  call void @llvm.lifetime.start.p0(ptr %src)
+  call void @llvm.lifetime.start.p0(ptr %dest)
+  %src.gep = getelementptr inbounds i8, ptr %src, i64 4
+  store i64 42, ptr %src.gep
+  call void @use_nocapture(ptr nocapture %src.gep)
+
+  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %dest, ptr align 4 %src.gep, i64 8, i1 false)
+
+  call void @use_nocapture(ptr nocapture %dest)
+
+  call void @llvm.lifetime.end.p0(ptr %src)
+  call void @llvm.lifetime.end.p0(ptr %dest)
+  ret void
+}
+
+; Test: load/store from GEP(src) to dest alloca
+; src = [8 x i8], dest = [4 x i8] align 4, load/store 4 bytes from src+4
+; SrcOffset(4) is a multiple of DestAlign(4), so optimization applies.
+define void @load_store_src_gep_to_dest_alloca() {
+; CHECK-LABEL: define void @load_store_src_gep_to_dest_alloca() {
+; CHECK-NEXT:    [[SRC:%.*]] = alloca [8 x i8], align 4
+; CHECK-NEXT:    [[SRC_GEP:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i64 4
+; CHECK-NEXT:    [[SRC_GEP1:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i64 4
+; CHECK-NEXT:    store i32 42, ptr [[SRC_GEP1]], align 4
+; CHECK-NEXT:    call void @use_nocapture(ptr captures(none) [[SRC_GEP1]])
+; CHECK-NEXT:    call void @use_nocapture(ptr captures(none) [[SRC_GEP]])
+; CHECK-NEXT:    ret void
+;
+  %src = alloca [8 x i8], align 4
+  %dest = alloca [4 x i8], align 4
+  call void @llvm.lifetime.start.p0(ptr %src)
+  call void @llvm.lifetime.start.p0(ptr %dest)
+  %src.gep = getelementptr inbounds i8, ptr %src, i64 4
+  store i32 42, ptr %src.gep
+  call void @use_nocapture(ptr nocapture %src.gep)
+
+  %val = load i32, ptr %src.gep
+  store i32 %val, ptr %dest
+
+  call void @use_nocapture(ptr nocapture %dest)
+
+  call void @llvm.lifetime.end.p0(ptr %src)
+  call void @llvm.lifetime.end.p0(ptr %dest)
+  ret void
+}
+
+; Test: both src and dest are direct allocas (no offset), same size
+; This is the basic stack-move case, included here for completeness.
+define void @memcpy_both_direct_allocas() {
+; CHECK-LABEL: define void @memcpy_both_direct_allocas() {
+; CHECK-NEXT:    [[SRC:%.*]] = alloca [8 x i8], align 8
+; CHECK-NEXT:    store i64 42, ptr [[SRC]], align 4
+; CHECK-NEXT:    call void @use_nocapture(ptr captures(none) [[SRC]])
+; CHECK-NEXT:    call void @use_nocapture(ptr captures(none) [[SRC]])
+; CHECK-NEXT:    ret void
+;
+  %src = alloca [8 x i8], align 4
+  %dest = alloca [8 x i8], align 8
+  call void @llvm.lifetime.start.p0(ptr %src)
+  call void @llvm.lifetime.start.p0(ptr %dest)
+  store i64 42, ptr %src
+  call void @use_nocapture(ptr nocapture %src)
+
+  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %dest, ptr align 4 %src, i64 8, i1 false)
+
+  call void @use_nocapture(ptr nocapture %dest)
+
+  call void @llvm.lifetime.end.p0(ptr %src)
+  call void @llvm.lifetime.end.p0(ptr %dest)
+  ret void
+}
+
+; Negative test: dest has offset (dest is GEP, not direct alloca)
+; The optimization requires DestOffset == 0.
+define void @no_optimize_dest_has_offset() {
+; CHECK-LABEL: define void @no_optimize_dest_has_offset() {
+; CHECK-NEXT:    [[SRC:%.*]] = alloca [16 x i8], align 4
+; CHECK-NEXT:    [[DEST:%.*]] = alloca [16 x i8], align 8
+; CHECK-NEXT:    call void @llvm.lifetime.start.p0(ptr [[SRC]])
+; CHECK-NEXT:    call void @llvm.lifetime.start.p0(ptr [[DEST]])
+; CHECK-NEXT:    [[SRC_GEP:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i64 8
+; CHECK-NEXT:    [[DEST_GEP:%.*]] = getelementptr inbounds i8, ptr [[DEST]], i64 8
+; CHECK-NEXT:    store i64 42, ptr [[SRC_GEP]], align 4
+; CHECK-NEXT:    call void @use_nocapture(ptr captures(none) [[SRC_GEP]])
+; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[DEST_GEP]], ptr align 4 [[SRC_GEP]], i64 8, i1 false)
+; CHECK-NEXT:    call void @use_nocapture(ptr captures(none) [[DEST_GEP]])
+; CHECK-NEXT:    call void @llvm.lifetime.end.p0(ptr [[SRC]])
+; CHECK-NEXT:    call void @llvm.lifetime.end.p0(ptr [[DEST]])
+; CHECK-NEXT:    ret void
+;
+  %src = alloca [16 x i8], align 4
+  %dest = alloca [16 x i8], align 8
+  call void @llvm.lifetime.start.p0(ptr %src)
+  call void @llvm.lifetime.start.p0(ptr %dest)
+  %src.gep = getelementptr inbounds i8, ptr %src, i64 8
+  %dest.gep = getelementptr inbounds i8, ptr %dest, i64 8
+  store i64 42, ptr %src.gep
+  call void @use_nocapture(ptr nocapture %src.gep)
+
+  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %dest.gep, ptr align 4 %src.gep, i64 8, i1 false)
+
+  call void @use_nocapture(ptr nocapture %dest.gep)
+
+  call void @llvm.lifetime.end.p0(ptr %src)
+  call void @llvm.lifetime.end.p0(ptr %dest)
+  ret void
+}
+
+; Negative test: copy doesn't cover entire dest alloca (Size != DestSize)
+; src = [12 x i8], dest = [16 x i8], copy only 8 bytes
+define void @no_optimize_partial_dest_copy() {
+; CHECK-LABEL: define void @no_optimize_partial_dest_copy() {
+; CHECK-NEXT:    [[SRC:%.*]] = alloca [12 x i8], align 4
+; CHECK-NEXT:    [[DEST:%.*]] = alloca [16 x i8], align 4
+; CHECK-NEXT:    call void @llvm.lifetime.start.p0(ptr [[SRC]])
+; CHECK-NEXT:    call void @llvm.lifetime.start.p0(ptr [[DEST]])
+; CHECK-NEXT:    [[SRC_GEP:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i64 4
+; CHECK-NEXT:    store i64 42, ptr [[SRC_GEP]], align 4
+; CHECK-NEXT:    call void @use_nocapture(ptr captures(none) [[SRC_GEP]])
+; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[DEST]], ptr align 4 [[SRC_GEP]], i64 8, i1 false)
+; CHECK-NEXT:    call void @use_nocapture(ptr captures(none) [[DEST]])
+; CHECK-NEXT:    call void @llvm.lifetime.end.p0(ptr [[SRC]])
+; CHECK-NEXT:    call void @llvm.lifetime.end.p0(ptr [[DEST]])
+; CHECK-NEXT:    ret void
+;
+  %src = alloca [12 x i8], align 4
+  %dest = alloca [16 x i8], align 4
+  call void @llvm.lifetime.start.p0(ptr %src)
+  call void @llvm.lifetime.start.p0(ptr %dest)
+  %src.gep = getelementptr inbounds i8, ptr %src, i64 4
+  store i64 42, ptr %src.gep
+  call void @use_nocapture(ptr nocapture %src.gep)
+
+  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %dest, ptr align 4 %src.gep, i64 8, i1 false)
+
+  call void @use_nocapture(ptr nocapture %dest)
+
+  call void @llvm.lifetime.end.p0(ptr %src)
+  call void @llvm.lifetime.end.p0(ptr %dest)
+  ret void
+}
+
+; Negative test: SrcOffset not a multiple of DestAlign
+; src = [12 x i8] with offset 4, dest = [8 x i8] align 8
+; SrcOffset(4) % DestAlign(8) = 4 != 0 -> rejected
+define void @no_optimize_alignment_mismatch() {
+; CHECK-LABEL: define void @no_optimize_alignment_mismatch() {
+; CHECK-NEXT:    [[SRC:%.*]] = alloca [12 x i8], align 4
+; CHECK-NEXT:    [[DEST:%.*]] = alloca [8 x i8], align 8
+; CHECK-NEXT:    call void @llvm.lifetime.start.p0(ptr [[SRC]])
+; CHECK-NEXT:    call void @llvm.lifetime.start.p0(ptr [[DEST]])
+; CHECK-NEXT:    [[SRC_GEP:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i64 4
+; CHECK-NEXT:    store i64 42, ptr [[SRC_GEP]], align 4
+; CHECK-NEXT:    call void @use_nocapture(ptr captures(none) [[SRC_GEP]])
+; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[DEST]], ptr align 4 [[SRC_GEP]], i64 8, i1 false)
+; CHECK-NEXT:    call void @use_nocapture(ptr captures(none) [[DEST]])
+; CHECK-NEXT:    call void @llvm.lifetime.end.p0(ptr [[SRC]])
+; CHECK-NEXT:    call void @llvm.lifetime.end.p0(ptr [[DEST]])
+; CHECK-NEXT:    ret void
+;
+  %src = alloca [12 x i8], align 4
+  %dest = alloca [8 x i8], align 8
+  call void @llvm.lifetime.start.p0(ptr %src)
+  call void @llvm.lifetime.start.p0(ptr %dest)
+  %src.gep = getelementptr inbounds i8, ptr %src, i64 4
+  store i64 42, ptr %src.gep
+  call void @use_nocapture(ptr nocapture %src.gep)
+
+  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %dest, ptr align 4 %src.gep, i64 8, i1 false)
+
+  call void @use_nocapture(ptr nocapture %dest)
+
+  call void @llvm.lifetime.end.p0(ptr %src)
+  call void @llvm.lifetime.end.p0(ptr %dest)
+  ret void
+}



More information about the llvm-commits mailing list