@@ -1703,19 +1703,19 @@ static void AddAlignmentAssumptions(CallBase &CB, InlineFunctionInfo &IFI) {
17031703}
17041704
17051705static void HandleByValArgumentInit (Type *ByValType, Value *Dst, Value *Src,
1706- Module *M, BasicBlock *InsertBlock,
1706+ MaybeAlign SrcAlign, Module *M,
1707+ BasicBlock *InsertBlock,
17071708 InlineFunctionInfo &IFI,
17081709 Function *CalledFunc) {
17091710 IRBuilder<> Builder (InsertBlock, InsertBlock->begin ());
17101711
17111712 Value *Size =
17121713 Builder.getInt64 (M->getDataLayout ().getTypeStoreSize (ByValType));
17131714
1714- // Always generate a memcpy of alignment 1 here because we don't know
1715- // the alignment of the src pointer. Other optimizations can infer
1716- // better alignment.
1717- CallInst *CI = Builder.CreateMemCpy (Dst, /* DstAlign*/ Align (1 ), Src,
1718- /* SrcAlign*/ Align (1 ), Size);
1715+ Align DstAlign = Dst->getPointerAlignment (M->getDataLayout ());
1716+
1717+ // Generate a memcpy with the correct alignments.
1718+ CallInst *CI = Builder.CreateMemCpy (Dst, DstAlign, Src, SrcAlign, Size);
17191719
17201720 // The verifier requires that all calls of debug-info-bearing functions
17211721 // from debug-info-bearing functions have a debug location (for inlining
@@ -2629,9 +2629,12 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
26292629 struct ByValInit {
26302630 Value *Dst;
26312631 Value *Src;
2632+ MaybeAlign SrcAlign;
26322633 Type *Ty;
26332634 };
2634- // Keep a list of pair (dst, src) to emit byval initializations.
2635+ // Keep a list of tuples (dst, src, src_align) to emit byval
2636+ // initializations. Src Alignment is only available though the callbase,
2637+ // therefore has to be saved.
26352638 SmallVector<ByValInit, 4 > ByValInits;
26362639
26372640 // When inlining a function that contains noalias scope metadata,
@@ -2661,8 +2664,9 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
26612664 &CB, CalledFunc, IFI,
26622665 CalledFunc->getParamAlign (ArgNo));
26632666 if (ActualArg != *AI)
2664- ByValInits.push_back (
2665- {ActualArg, (Value *)*AI, CB.getParamByValType (ArgNo)});
2667+ ByValInits.push_back ({ActualArg, (Value *)*AI,
2668+ CB.getParamAlign (ArgNo),
2669+ CB.getParamByValType (ArgNo)});
26662670 }
26672671
26682672 VMap[&*I] = ActualArg;
@@ -2712,8 +2716,9 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
27122716
27132717 // Inject byval arguments initialization.
27142718 for (ByValInit &Init : ByValInits)
2715- HandleByValArgumentInit (Init.Ty , Init.Dst , Init.Src , Caller->getParent (),
2716- &*FirstNewBlock, IFI, CalledFunc);
2719+ HandleByValArgumentInit (Init.Ty , Init.Dst , Init.Src , Init.SrcAlign ,
2720+ Caller->getParent (), &*FirstNewBlock, IFI,
2721+ CalledFunc);
27172722
27182723 std::optional<OperandBundleUse> ParentDeopt =
27192724 CB.getOperandBundle (LLVMContext::OB_deopt);
0 commit comments