1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=memcpyopt -S %s | FileCheck %s
4 declare void @init(ptr nocapture sret(i64) align 8)
6 declare i1 @check(ptr readonly byval(i64) align 8) readonly argmemonly
8 declare void @clobber(ptr) argmemonly
10 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
11 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
12 declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg)
14 ; %a.2's lifetime ends before the call to @check. Cannot replace
15 ; %a.1 with %a.2 in the call to @check.
16 define i1 @alloca_forwarding_lifetime_end_clobber() {
17 ; CHECK-LABEL: @alloca_forwarding_lifetime_end_clobber(
19 ; CHECK-NEXT: [[A_1:%.*]] = alloca i64, align 8
20 ; CHECK-NEXT: [[A_2:%.*]] = alloca i64, align 8
21 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 8, ptr [[A_2]])
22 ; CHECK-NEXT: call void @init(ptr sret(i64) align 8 [[A_2]])
23 ; CHECK-NEXT: store i8 0, ptr [[A_2]], align 1
24 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[A_1]], ptr [[A_2]], i64 8, i1 false)
25 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 8, ptr [[A_2]])
26 ; CHECK-NEXT: [[CALL:%.*]] = call i1 @check(ptr byval(i64) align 8 [[A_1]])
27 ; CHECK-NEXT: ret i1 [[CALL]]
30 %a.1 = alloca i64, align 8
31 %a.2 = alloca i64, align 8
32 call void @llvm.lifetime.start.p0(i64 8, ptr %a.2)
33 call void @init(ptr sret(i64) align 8 %a.2)
35 call void @llvm.memcpy.p0.p0.i64(ptr %a.1, ptr %a.2, i64 8, i1 false)
36 call void @llvm.lifetime.end.p0(i64 8, ptr %a.2)
37 ;call void @clobber(ptr %a.2)
38 %call = call i1 @check(ptr byval(i64) align 8 %a.1)
42 ; There is a call clobbering %a.2 before the call to @check. Cannot replace
43 ; %a.1 with %a.2 in the call to @check.
44 define i1 @alloca_forwarding_call_clobber() {
45 ; CHECK-LABEL: @alloca_forwarding_call_clobber(
47 ; CHECK-NEXT: [[A_1:%.*]] = alloca i64, align 8
48 ; CHECK-NEXT: [[A_2:%.*]] = alloca i64, align 8
49 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 8, ptr [[A_2]])
50 ; CHECK-NEXT: call void @init(ptr sret(i64) align 8 [[A_2]])
51 ; CHECK-NEXT: store i8 0, ptr [[A_2]], align 1
52 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[A_1]], ptr [[A_2]], i64 8, i1 false)
53 ; CHECK-NEXT: call void @clobber(ptr [[A_2]])
54 ; CHECK-NEXT: [[CALL:%.*]] = call i1 @check(ptr byval(i64) align 8 [[A_1]])
55 ; CHECK-NEXT: ret i1 [[CALL]]
58 %a.1 = alloca i64, align 8
59 %a.2 = alloca i64, align 8
60 call void @llvm.lifetime.start.p0(i64 8, ptr %a.2)
61 call void @init(ptr sret(i64) align 8 %a.2)
63 call void @llvm.memcpy.p0.p0.i64(ptr %a.1, ptr %a.2, i64 8, i1 false)
64 call void @clobber(ptr %a.2)
65 %call = call i1 @check(ptr byval(i64) align 8 %a.1)
69 define i1 @alloca_forwarding_call_clobber_after() {
70 ; CHECK-LABEL: @alloca_forwarding_call_clobber_after(
72 ; CHECK-NEXT: [[A_1:%.*]] = alloca i64, align 8
73 ; CHECK-NEXT: [[A_2:%.*]] = alloca i64, align 8
74 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 8, ptr [[A_2]])
75 ; CHECK-NEXT: call void @init(ptr sret(i64) align 8 [[A_2]])
76 ; CHECK-NEXT: store i8 0, ptr [[A_2]], align 1
77 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[A_1]], ptr [[A_2]], i64 8, i1 false)
78 ; CHECK-NEXT: [[CALL:%.*]] = call i1 @check(ptr byval(i64) align 8 [[A_2]])
79 ; CHECK-NEXT: call void @clobber(ptr [[A_2]])
80 ; CHECK-NEXT: ret i1 [[CALL]]
83 %a.1 = alloca i64, align 8
84 %a.2 = alloca i64, align 8
85 call void @llvm.lifetime.start.p0(i64 8, ptr %a.2)
86 call void @init(ptr sret(i64) align 8 %a.2)
88 call void @llvm.memcpy.p0.p0.i64(ptr %a.1, ptr %a.2, i64 8, i1 false)
89 %call = call i1 @check(ptr byval(i64) align 8 %a.1)
90 call void @clobber(ptr %a.2)
94 define i1 @alloca_forwarding_unrelated_call_noclobber() {
95 ; CHECK-LABEL: @alloca_forwarding_unrelated_call_noclobber(
97 ; CHECK-NEXT: [[A_1:%.*]] = alloca i64, align 8
98 ; CHECK-NEXT: [[A_2:%.*]] = alloca i64, align 8
99 ; CHECK-NEXT: [[A_3:%.*]] = alloca i64, align 8
100 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 8, ptr [[A_2]])
101 ; CHECK-NEXT: call void @init(ptr sret(i64) align 8 [[A_2]])
102 ; CHECK-NEXT: store i8 0, ptr [[A_2]], align 1
103 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[A_1]], ptr [[A_2]], i64 8, i1 false)
104 ; CHECK-NEXT: call void @clobber(ptr [[A_3]])
105 ; CHECK-NEXT: [[CALL:%.*]] = call i1 @check(ptr byval(i64) align 8 [[A_2]])
106 ; CHECK-NEXT: ret i1 [[CALL]]
109 %a.1 = alloca i64, align 8
110 %a.2 = alloca i64, align 8
111 %a.3 = alloca i64, align 8
112 call void @llvm.lifetime.start.p0(i64 8, ptr %a.2)
113 call void @init(ptr sret(i64) align 8 %a.2)
115 call void @llvm.memcpy.p0.p0.i64(ptr %a.1, ptr %a.2, i64 8, i1 false)
116 call void @clobber(ptr %a.3)
117 %call = call i1 @check(ptr byval(i64) align 8 %a.1)