diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h --- a/llvm/include/llvm/CodeGen/TargetLowering.h +++ b/llvm/include/llvm/CodeGen/TargetLowering.h @@ -125,6 +125,8 @@ static MemOp Copy(uint64_t Size, bool DstAlignCanChange, unsigned DstAlign, unsigned SrcAlign, bool IsVolatile, bool MemcpyStrSrc = false) { + assert(DstAlign && "Destination alignment should be set"); + assert(SrcAlign && "Source alignment should be set"); return { /*.Size =*/Size, /*.DstAlign =*/DstAlignCanChange ? 0 : DstAlign, @@ -137,6 +139,7 @@ } static MemOp Set(uint64_t Size, bool DstAlignCanChange, unsigned DstAlign, bool IsZeroMemset, bool IsVolatile) { + assert(DstAlign && "Destination alignment should be set"); return { /*.Size =*/Size, /*.DstAlign =*/DstAlignCanChange ? 0 : DstAlign, diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -5908,12 +5908,14 @@ bool CopyFromConstant = isMemSrcFromConstant(Src, Slice); bool isZeroConstant = CopyFromConstant && Slice.Array == nullptr; unsigned Limit = AlwaysInline ? ~0U : TLI.getMaxStoresPerMemcpy(OptSize); + const MemOp Op = isZeroConstant + ? MemOp::Set(Size, DstAlignCanChange, Alignment, + /*IsZeroMemset*/ true, isVol) + : MemOp::Copy(Size, DstAlignCanChange, Alignment, + SrcAlign, isVol, CopyFromConstant); if (!TLI.findOptimalMemOpLowering( - MemOps, Limit, - MemOp::Copy(Size, DstAlignCanChange, Alignment, - isZeroConstant ? 0 : SrcAlign, isVol, CopyFromConstant), - DstPtrInfo.getAddrSpace(), SrcPtrInfo.getAddrSpace(), - MF.getFunction().getAttributes())) + MemOps, Limit, Op, DstPtrInfo.getAddrSpace(), + SrcPtrInfo.getAddrSpace(), MF.getFunction().getAttributes())) return SDValue(); if (DstAlignCanChange) { diff --git a/llvm/test/CodeGen/AArch64/memcpy-f128.ll b/llvm/test/CodeGen/AArch64/memcpy-f128.ll --- a/llvm/test/CodeGen/AArch64/memcpy-f128.ll +++ b/llvm/test/CodeGen/AArch64/memcpy-f128.ll @@ -7,9 +7,6 @@ define void @test1() { ; CHECK-LABEL: @test1 -; CHECK: adrp -; CHECK: ldr q0 -; CHECK: str q0 ; CHECK: ret entry: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 undef, i8* align 8 bitcast (%structA* @stubA to i8*), i64 48, i1 false)