1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=memcpyopt -S -verify-memoryssa | FileCheck %s
4 ; performCallSlotOptzn in MemCpy should not exchange the calls to
5 ; @llvm.lifetime.start and @llvm.memcpy.
7 declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture readonly, i64, i1)
8 declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
9 declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
11 define void @call_slot(ptr nocapture dereferenceable(16) %arg1) {
12 ; CHECK-LABEL: @call_slot(
14 ; CHECK-NEXT: [[TMP:%.*]] = alloca [8 x i8], align 8
15 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 16, ptr [[TMP]])
16 ; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds i8, ptr [[TMP]], i64 7
17 ; CHECK-NEXT: store i8 0, ptr [[TMP10]], align 1
18 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 16, ptr [[TMP]])
19 ; CHECK-NEXT: ret void
22 %tmp = alloca [8 x i8], align 8
23 call void @llvm.lifetime.start.p0(i64 16, ptr %tmp)
24 %tmp10 = getelementptr inbounds i8, ptr %tmp, i64 7
25 store i8 0, ptr %tmp10, align 1
26 call void @llvm.memcpy.p0.p0.i64(ptr align 8 %arg1, ptr align 8 %tmp, i64 16, i1 false)
27 call void @llvm.lifetime.end.p0(i64 16, ptr %tmp)
31 define void @memcpy_memcpy_across_lifetime(ptr noalias %p1, ptr noalias %p2, ptr noalias %p3) {
32 ; CHECK-LABEL: @memcpy_memcpy_across_lifetime(
33 ; CHECK-NEXT: [[A:%.*]] = alloca [16 x i8], align 1
34 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 16, ptr [[A]])
35 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[A]], ptr [[P1:%.*]], i64 16, i1 false)
36 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[P1]], ptr [[P2:%.*]], i64 16, i1 false)
37 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[P2]], ptr [[A]], i64 16, i1 false)
38 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 16, ptr [[A]])
39 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[P3:%.*]], ptr [[P2]], i64 16, i1 false)
40 ; CHECK-NEXT: ret void
43 call void @llvm.lifetime.start.p0(i64 16, ptr %a)
44 call void @llvm.memcpy.p0.p0.i64(ptr %a, ptr %p1, i64 16, i1 false)
45 call void @llvm.memcpy.p0.p0.i64(ptr %p1, ptr %p2, i64 16, i1 false)
46 call void @llvm.memcpy.p0.p0.i64(ptr %p2, ptr %a, i64 16, i1 false)
47 call void @llvm.lifetime.end.p0(i64 16, ptr %a)
48 call void @llvm.memcpy.p0.p0.i64(ptr %p3, ptr %p2, i64 16, i1 false)
52 declare void @call(ptr)
54 define i32 @call_slot_move_lifetime_start() {
55 ; CHECK-LABEL: @call_slot_move_lifetime_start(
56 ; CHECK-NEXT: [[TMP:%.*]] = alloca i32, align 4
57 ; CHECK-NEXT: [[DST:%.*]] = alloca i32, align 4
58 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr [[DST]])
59 ; CHECK-NEXT: call void @call(ptr [[DST]])
60 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr [[DST]])
61 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[DST]], align 4
62 ; CHECK-NEXT: ret i32 [[V]]
66 call void @call(ptr %tmp)
67 call void @llvm.lifetime.start.p0(i64 4, ptr %dst)
68 call void @llvm.memcpy.p0.p0.i64(ptr align 4 %dst, ptr align 4 %tmp, i64 4, i1 false)
69 call void @llvm.lifetime.end.p0(i64 4, ptr %dst)
70 %v = load i32, ptr %dst
74 define i32 @call_slot_two_lifetime_starts() {
75 ; CHECK-LABEL: @call_slot_two_lifetime_starts(
76 ; CHECK-NEXT: [[TMP:%.*]] = alloca i32, align 4
77 ; CHECK-NEXT: [[DST:%.*]] = alloca i32, align 4
78 ; CHECK-NEXT: call void @call(ptr [[TMP]])
79 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr [[DST]])
80 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr [[DST]])
81 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[DST]], ptr align 4 [[TMP]], i64 4, i1 false)
82 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr [[DST]])
83 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[DST]], align 4
84 ; CHECK-NEXT: ret i32 [[V]]
88 call void @call(ptr %tmp)
89 call void @llvm.lifetime.start.p0(i64 4, ptr %dst)
90 call void @llvm.lifetime.start.p0(i64 4, ptr %dst)
91 call void @llvm.memcpy.p0.p0.i64(ptr align 4 %dst, ptr align 4 %tmp, i64 4, i1 false)
92 call void @llvm.lifetime.end.p0(i64 4, ptr %dst)
93 %v = load i32, ptr %dst
97 define i32 @call_slot_clobber_before_lifetime_start() {
98 ; CHECK-LABEL: @call_slot_clobber_before_lifetime_start(
99 ; CHECK-NEXT: [[TMP:%.*]] = alloca i32, align 4
100 ; CHECK-NEXT: [[DST:%.*]] = alloca i32, align 4
101 ; CHECK-NEXT: call void @call(ptr [[TMP]])
102 ; CHECK-NEXT: store i32 0, ptr [[DST]], align 4
103 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr [[DST]])
104 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[DST]], ptr align 4 [[TMP]], i64 4, i1 false)
105 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr [[DST]])
106 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[DST]], align 4
107 ; CHECK-NEXT: ret i32 [[V]]
111 call void @call(ptr %tmp)
112 store i32 0, ptr %dst
113 call void @llvm.lifetime.start.p0(i64 4, ptr %dst)
114 call void @llvm.memcpy.p0.p0.i64(ptr align 4 %dst, ptr align 4 %tmp, i64 4, i1 false)
115 call void @llvm.lifetime.end.p0(i64 4, ptr %dst)
116 %v = load i32, ptr %dst
120 define void @call_slot_lifetime_bitcast(ptr %ptr) {
121 ; CHECK-LABEL: @call_slot_lifetime_bitcast(
122 ; CHECK-NEXT: [[TMP1:%.*]] = alloca i32, align 4
123 ; CHECK-NEXT: [[TMP2:%.*]] = alloca i32, align 4
124 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[TMP2]], ptr align 4 [[PTR:%.*]], i64 4, i1 false)
125 ; CHECK-NEXT: [[TMP1_CAST:%.*]] = bitcast ptr [[TMP1]] to ptr
126 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr nonnull [[TMP1_CAST]])
127 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[TMP1]], ptr align 4 [[PTR]], i64 4, i1 false)
128 ; CHECK-NEXT: ret void
132 call void @llvm.memcpy.p0.p0.i64(ptr align 8 %tmp2, ptr align 4 %ptr, i64 4, i1 false)
133 %tmp1.cast = bitcast ptr %tmp1 to ptr
134 call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %tmp1.cast)
135 call void @llvm.memcpy.p0.p0.i64(ptr align 4 %tmp1.cast, ptr align 4 %tmp2, i64 4, i1 false)