Skip to content

Commit

Permalink
[MemCpyOpt] Fix metadata merging during call slot optimization
Browse files Browse the repository at this point in the history
Call slot optimization currently merges the metadata between the
call and the load. However, we also need to merge in the metadata
of the store.

Part of the reason why we might have gotten away with this
previously is that usually the load and the store are the same
instruction (a memcpy), this can only happen if call slot
optimization occurs on an actual load/store pair.

This addresses the issue reported in
https://reviews.llvm.org/D115615#3251386.

Differential Revision: https://reviews.llvm.org/D117679
  • Loading branch information
nikic committed Jan 20, 2022
1 parent 22ee510 commit d7bff2e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
Expand Up @@ -1022,6 +1022,8 @@ bool MemCpyOptPass::performCallSlotOptzn(Instruction *cpyLoad,
LLVMContext::MD_invariant_group,
LLVMContext::MD_access_group};
combineMetadata(C, cpyLoad, KnownIDs, true);
if (cpyLoad != cpyStore)
combineMetadata(C, cpyStore, KnownIDs, true);

++NumCallSlot;
return true;
Expand Down
5 changes: 3 additions & 2 deletions llvm/test/Transforms/MemCpyOpt/callslot_noalias.ll
Expand Up @@ -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]]
;
Expand Down

0 comments on commit d7bff2e

Please sign in to comment.