Skip to content

Commit

Permalink
[MemCpyOpt] add noalias metadata on lifetime intrinsic test case for …
Browse files Browse the repository at this point in the history
…stack-move optimization(NFC)
  • Loading branch information
khei4 committed Jul 22, 2023
1 parent 8b4d733 commit d878916
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions llvm/test/Transforms/MemCpyOpt/stack-move.ll
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,37 @@ define void @remove_alloca_metadata() {
}

; TODO: Merge alloca and remove memcpy.
; Tests that we remove scoped noalias metadata from a call.
; And confirm that don't crash on noalias metadata on lifetime markers.
define void @noalias_on_lifetime() {
; CHECK-LABEL: define void @noalias_on_lifetime() {
; CHECK-NEXT: [[SRC:%.*]] = alloca [[STRUCT_FOO:%.*]], align 4
; CHECK-NEXT: [[DEST:%.*]] = alloca [[STRUCT_FOO]], align 4
; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 12, ptr nocapture [[SRC]])
; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 12, ptr nocapture [[DEST]])
; CHECK-NEXT: store [[STRUCT_FOO]] { i32 10, i32 20, i32 30 }, ptr [[SRC]], align 4
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @use_nocapture(ptr nocapture [[SRC]]), !alias.scope !0
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[DEST]], ptr align 4 [[SRC]], i64 12, i1 false)
; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 12, ptr nocapture [[SRC]]), !alias.scope !0
; CHECK-NEXT: [[TMP2:%.*]] = call i32 @use_nocapture(ptr nocapture [[DEST]]), !noalias !0
; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 12, ptr nocapture [[DEST]]), !noalias !0
; CHECK-NEXT: ret void
;
%src = alloca %struct.Foo, align 4
%dest = alloca %struct.Foo, align 4
call void @llvm.lifetime.start.p0(i64 12, ptr nocapture %src)
call void @llvm.lifetime.start.p0(i64 12, ptr nocapture %dest)
store %struct.Foo { i32 10, i32 20, i32 30 }, ptr %src
%1 = call i32 @use_nocapture(ptr nocapture %src), !alias.scope !2

call void @llvm.memcpy.p0.p0.i64(ptr align 4 %dest, ptr align 4 %src, i64 12, i1 false)

call void @llvm.lifetime.end.p0(i64 12, ptr nocapture %src), !alias.scope !2
%2 = call i32 @use_nocapture(ptr nocapture %dest), !noalias !2
call void @llvm.lifetime.end.p0(i64 12, ptr nocapture %dest), !noalias !2
ret void
}

; Tests that we can merge alloca if the dest and src has only refs except lifetime intrinsics.
define void @src_ref_dest_ref_after_copy() {
; CHECK-LABEL: define void @src_ref_dest_ref_after_copy() {
Expand Down

0 comments on commit d878916

Please sign in to comment.