1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -aa-pipeline=basic-aa -passes=gvn,dse -S | FileCheck %s
3 target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
5 declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
7 declare void @external(ptr)
9 define i32 @test0(ptr %P) {
10 ; CHECK-LABEL: @test0(
11 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
12 ; CHECK-NEXT: call void @external(ptr [[A]])
13 ; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr [[P:%.*]], i8 0, i32 42, i1 false)
14 ; CHECK-NEXT: ret i32 0
17 call void @external(ptr %A)
21 call void @llvm.memset.p0.i32(ptr %P, i8 0, i32 42, i1 false)
28 ; CHECK-LABEL: @test1(
29 ; CHECK-NEXT: ret i8 2
34 store i8 2, ptr %B ;; Not written to by memcpy
36 call void @llvm.memcpy.p0.p0.i8(ptr %A, ptr %B, i8 -1, i1 false)
42 define i8 @test2(ptr %P) {
43 ; CHECK-LABEL: @test2(
44 ; CHECK-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 127
45 ; CHECK-NEXT: store i8 1, ptr [[P2]], align 1
46 ; CHECK-NEXT: call void @llvm.memset.p0.i8(ptr [[P]], i8 2, i8 127, i1 false)
47 ; CHECK-NEXT: ret i8 1
49 %P2 = getelementptr i8, ptr %P, i32 127
50 store i8 1, ptr %P2 ;; Not dead across memset
51 call void @llvm.memset.p0.i8(ptr %P, i8 2, i8 127, i1 false)
56 define i8 @test2a(ptr %P) {
57 ; CHECK-LABEL: @test2a(
58 ; CHECK-NEXT: call void @llvm.memset.p0.i8(ptr [[P:%.*]], i8 2, i8 127, i1 false)
59 ; CHECK-NEXT: ret i8 2
61 %P2 = getelementptr i8, ptr %P, i32 126
63 store i8 1, ptr %P2 ;; Dead, clobbered by memset.
65 call void @llvm.memset.p0.i8(ptr %P, i8 2, i8 127, i1 false)
70 define void @test3(ptr %P, i8 %X) {
71 ; CHECK-LABEL: @test3(
72 ; CHECK-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 2
73 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 1, ptr [[P]])
74 ; CHECK-NEXT: store i8 2, ptr [[P2]], align 1
75 ; CHECK-NEXT: ret void
77 %Y = add i8 %X, 1 ;; Dead, because the only use (the store) is dead.
79 %P2 = getelementptr i8, ptr %P, i32 2
80 store i8 %Y, ptr %P2 ;; Not read by lifetime.end, should be removed.
81 call void @llvm.lifetime.end.p0(i64 1, ptr %P)
86 define void @test3a(ptr %P, i8 %X) {
87 ; CHECK-LABEL: @test3a(
88 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 10, ptr [[P:%.*]])
89 ; CHECK-NEXT: ret void
91 %Y = add i8 %X, 1 ;; Dead, because the only use (the store) is dead.
93 %P2 = getelementptr i8, ptr %P, i32 2
95 call void @llvm.lifetime.end.p0(i64 10, ptr %P)
99 @G1 = external global i32
100 @G2 = external global [4000 x i32]
102 define i32 @test4(ptr %P) {
103 ; CHECK-LABEL: @test4(
104 ; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr @G2, i8 0, i32 4000, i1 false)
105 ; CHECK-NEXT: ret i32 0
107 %tmp = load i32, ptr @G1
108 call void @llvm.memset.p0.i32(ptr @G2, i8 0, i32 4000, i1 false)
109 %tmp2 = load i32, ptr @G1
110 %sub = sub i32 %tmp2, %tmp
114 ; Verify that basicaa is handling variable length memcpy, knowing it doesn't
116 define i32 @test5(ptr %P, i32 %Len) {
117 ; CHECK-LABEL: @test5(
118 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr @G2, ptr @G1, i32 [[LEN:%.*]], i1 false)
119 ; CHECK-NEXT: ret i32 0
121 %tmp = load i32, ptr @G1
122 call void @llvm.memcpy.p0.p0.i32(ptr @G2, ptr @G1, i32 %Len, i1 false)
123 %tmp2 = load i32, ptr @G1
124 %sub = sub i32 %tmp2, %tmp
128 define i8 @test6(ptr %p, ptr noalias %a) {
129 ; CHECK-LABEL: @test6(
130 ; CHECK-NEXT: [[X:%.*]] = load i8, ptr [[A:%.*]], align 1
131 ; CHECK-NEXT: [[T:%.*]] = va_arg ptr [[P:%.*]], float
132 ; CHECK-NEXT: [[Z:%.*]] = add i8 [[X]], [[X]]
133 ; CHECK-NEXT: ret i8 [[Z]]
136 %t = va_arg ptr %p, float
143 declare void @test7decl(ptr nocapture %x)
144 define i32 @test7() nounwind uwtable ssp {
145 ; CHECK-LABEL: @test7(
147 ; CHECK-NEXT: [[X:%.*]] = alloca i32, align 4
148 ; CHECK-NEXT: store i32 0, ptr [[X]], align 4
149 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i32, ptr [[X]], i64 1
150 ; CHECK-NEXT: call void @test7decl(ptr [[ADD_PTR]])
151 ; CHECK-NEXT: [[TMP:%.*]] = load i32, ptr [[X]], align 4
152 ; CHECK-NEXT: ret i32 [[TMP]]
155 %x = alloca i32, align 4
156 store i32 0, ptr %x, align 4
157 %add.ptr = getelementptr inbounds i32, ptr %x, i64 1
158 call void @test7decl(ptr %add.ptr)
159 %tmp = load i32, ptr %x, align 4
163 ;; Check that aa correctly handles functions marked with argmemonly
165 declare i32 @func_argmemonly(ptr %P) argmemonly
167 ;; Can not remove redundant load, function may write to it.
169 define i32 @test8(ptr %P) {
170 ; CHECK-LABEL: @test8(
171 ; CHECK-NEXT: [[V1:%.*]] = load i32, ptr [[P:%.*]], align 4
172 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @func_argmemonly(ptr [[P]])
173 ; CHECK-NEXT: [[V2:%.*]] = load i32, ptr [[P]], align 4
174 ; CHECK-NEXT: [[DIFF:%.*]] = sub i32 [[V1]], [[V2]]
175 ; CHECK-NEXT: ret i32 [[DIFF]]
177 %V1 = load i32, ptr %P
178 call i32 @func_argmemonly(ptr %P)
179 %V2 = load i32, ptr %P
180 %Diff = sub i32 %V1, %V2
184 ;; In this case load can be removed, function clobbers only %P2.
185 define i32 @test9(ptr %P, ptr noalias %P2) {
186 ; CHECK-LABEL: @test9(
187 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @func_argmemonly(ptr [[P2:%.*]])
188 ; CHECK-NEXT: ret i32 0
190 %V1 = load i32, ptr %P
191 call i32 @func_argmemonly(ptr %P2)
192 %V2 = load i32, ptr %P
193 %Diff = sub i32 %V1, %V2
197 ;; In this case load can *not* be removed. Function clobers only %P2 but it may
199 define i32 @test10(ptr %P, ptr %P2) {
200 ; CHECK-LABEL: @test10(
201 ; CHECK-NEXT: [[V1:%.*]] = load i32, ptr [[P:%.*]], align 4
202 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @func_argmemonly(ptr [[P2:%.*]])
203 ; CHECK-NEXT: [[V2:%.*]] = load i32, ptr [[P]], align 4
204 ; CHECK-NEXT: [[DIFF:%.*]] = sub i32 [[V1]], [[V2]]
205 ; CHECK-NEXT: ret i32 [[DIFF]]
207 %V1 = load i32, ptr %P
208 call i32 @func_argmemonly(ptr %P2)
209 %V2 = load i32, ptr %P
210 %Diff = sub i32 %V1, %V2
214 define i32 @test11(ptr %P, ptr %P2) {
215 ; CHECK-LABEL: @test11(
216 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @func_argmemonly(ptr readonly [[P2:%.*]])
217 ; CHECK-NEXT: ret i32 0
219 %V1 = load i32, ptr %P
220 call i32 @func_argmemonly(ptr readonly %P2)
221 %V2 = load i32, ptr %P
222 %Diff = sub i32 %V1, %V2
227 declare i32 @func_argmemonly_two_args(ptr %P, ptr %P2) argmemonly
229 define i32 @test12(ptr %P, ptr %P2, ptr %P3) {
230 ; CHECK-LABEL: @test12(
231 ; CHECK-NEXT: [[V1:%.*]] = load i32, ptr [[P:%.*]], align 4
232 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @func_argmemonly_two_args(ptr readonly [[P2:%.*]], ptr [[P3:%.*]])
233 ; CHECK-NEXT: [[V2:%.*]] = load i32, ptr [[P]], align 4
234 ; CHECK-NEXT: [[DIFF:%.*]] = sub i32 [[V1]], [[V2]]
235 ; CHECK-NEXT: ret i32 [[DIFF]]
237 %V1 = load i32, ptr %P
238 call i32 @func_argmemonly_two_args(ptr readonly %P2, ptr %P3)
239 %V2 = load i32, ptr %P
240 %Diff = sub i32 %V1, %V2
244 define i32 @test13(ptr %P, ptr %P2) {
245 ; CHECK-LABEL: @test13(
246 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @func_argmemonly(ptr readnone [[P2:%.*]])
247 ; CHECK-NEXT: ret i32 0
249 %V1 = load i32, ptr %P
250 call i32 @func_argmemonly(ptr readnone %P2)
251 %V2 = load i32, ptr %P
252 %Diff = sub i32 %V1, %V2
256 declare void @llvm.memset.p0.i32(ptr nocapture, i8, i32, i1) nounwind
257 declare void @llvm.memset.p0.i8(ptr nocapture, i8, i8, i1) nounwind
258 declare void @llvm.memcpy.p0.p0.i8(ptr nocapture, ptr nocapture, i8, i1) nounwind
259 declare void @llvm.memcpy.p0.p0.i32(ptr nocapture, ptr nocapture, i32, i1) nounwind