diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp --- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -1022,6 +1022,8 @@ LLVMContext::MD_invariant_group, LLVMContext::MD_access_group}; combineMetadata(C, cpyLoad, KnownIDs, true); + if (cpyLoad != cpyStore) + combineMetadata(C, cpyStore, KnownIDs, true); ++NumCallSlot; return true; diff --git a/llvm/test/Transforms/MemCpyOpt/callslot_noalias.ll b/llvm/test/Transforms/MemCpyOpt/callslot_noalias.ll --- a/llvm/test/Transforms/MemCpyOpt/callslot_noalias.ll +++ b/llvm/test/Transforms/MemCpyOpt/callslot_noalias.ll @@ -3,11 +3,12 @@ declare void @func(i8* %dst) -; TODO: The noalias metadata on the call is currently incorrect. +; The noalias metadata from the call, the load and the store should be merged, +; so that no metadata is left on the call. define i8 @test(i8* dereferenceable(1) noalias %dst) { ; CHECK-LABEL: @test( ; CHECK-NEXT: [[TMP:%.*]] = alloca i8, align 1 -; CHECK-NEXT: call void @func(i8* nocapture [[DST:%.*]]) #[[ATTR0:[0-9]+]], !noalias !0 +; CHECK-NEXT: call void @func(i8* nocapture [[DST:%.*]]) #[[ATTR0:[0-9]+]]{{$}} ; CHECK-NEXT: [[V2:%.*]] = load i8, i8* [[DST]], align 1, !alias.scope !0 ; CHECK-NEXT: ret i8 [[V2]] ;