Skip to content

Commit

Permalink
[MemCpyOpt] Combine alias metadatas when replacing byval arguments (#…
Browse files Browse the repository at this point in the history
…70580)

Fixes #70578.

(cherry picked from commit 0c4f326)
  • Loading branch information
DianQK authored and tru committed Oct 30, 2023
1 parent 2b82ec7 commit bb29e1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@ bool MemCpyOptPass::processByValArgument(CallBase &CB, unsigned ArgNo) {
<< " " << CB << "\n");

// Otherwise we're good! Update the byval argument.
combineAAMetadata(&CB, MDep);
CB.setArgOperand(ArgNo, MDep->getSource());
++NumMemCpyInstr;
return true;
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/Transforms/MemCpyOpt/memcpy.ll
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ declare void @f1(ptr nocapture sret(%struct.big))
declare void @f2(ptr)

declare void @f(ptr)
declare void @f_byval(ptr byval(i32))
declare void @f_full_readonly(ptr nocapture noalias readonly)

define void @immut_param(ptr align 4 noalias %val) {
Expand Down Expand Up @@ -709,6 +710,19 @@ define void @immut_param_noalias_metadata(ptr align 4 byval(i32) %ptr) {
ret void
}

define void @byval_param_noalias_metadata(ptr align 4 byval(i32) %ptr) {
; CHECK-LABEL: @byval_param_noalias_metadata(
; CHECK-NEXT: store i32 1, ptr [[PTR:%.*]], align 4, !noalias !0
; CHECK-NEXT: call void @f_byval(ptr byval(i32) align 4 [[PTR]])
; CHECK-NEXT: ret void
;
%tmp = alloca i32, align 4
store i32 1, ptr %ptr, !noalias !2
call void @llvm.memcpy.p0.p0.i64(ptr align 4 %tmp, ptr align 4 %ptr, i64 4, i1 false)
call void @f_byval(ptr align 4 byval(i32) %tmp), !alias.scope !2
ret void
}

!0 = !{!0}
!1 = !{!1, !0}
!2 = !{!1}

0 comments on commit bb29e1e

Please sign in to comment.