1 ; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 < %s | FileCheck %s
12 @G = external global i8*
14 ; CHECK: define i8* @foo()
16 %1 = tail call noalias i8* @malloc(i64 4)
17 store i8* %1, i8** @G, align 8
21 declare noalias i8* @malloc(i64)
24 ; call noalias function in return instruction.
26 ; CHECK: define noalias i8* @return_noalias()
27 define i8* @return_noalias(){
28 %1 = tail call noalias i8* @malloc(i64 4)
32 define void @nocapture(i8* %a){
36 ; CHECK: define noalias i8* @return_noalias_looks_like_capture()
37 define i8* @return_noalias_looks_like_capture(){
38 %1 = tail call noalias i8* @malloc(i64 4)
39 call void @nocapture(i8* %1)
46 ; CHECK: define i8* @call_alias()
48 define i8* @call_alias(){
49 %1 = tail call i8* @alias()
68 ; CHECK: define i8* @bar()
69 define i8* @bar() nounwind uwtable {
70 %1 = tail call i8* (...) @baz()
74 ; CHECK: define noalias i8* @foo1(i32 %0)
75 define i8* @foo1(i32 %0) nounwind uwtable {
76 %2 = icmp eq i32 %0, 0
77 br i1 %2, label %5, label %3
80 %4 = tail call i8* (...) @baz()
84 %6 = tail call noalias i8* @malloc(i64 4)
88 declare i8* @baz(...) nounwind uwtable
92 ; Returning global pointer. Should not be noalias.
93 ; CHECK: define nonnull align 8 dereferenceable(8) i8** @getter()
94 define i8** @getter() {
98 ; Returning global pointer. Should not be noalias.
99 ; CHECK: define nonnull align 8 dereferenceable(8) i8** @calle1()
100 define i8** @calle1(){
101 %1 = call i8** @getter()
106 declare noalias i8* @strdup(i8* nocapture) nounwind
108 ; CHECK: define noalias i8* @test6()
109 define i8* @test6() nounwind uwtable ssp {
110 %x = alloca [2 x i8], align 1
111 %arrayidx = getelementptr inbounds [2 x i8], [2 x i8]* %x, i64 0, i64 0
112 store i8 97, i8* %arrayidx, align 1
113 %arrayidx1 = getelementptr inbounds [2 x i8], [2 x i8]* %x, i64 0, i64 1
114 store i8 0, i8* %arrayidx1, align 1
115 %call = call noalias i8* @strdup(i8* %arrayidx) nounwind
121 ; CHECK: define noalias i8* @test7()
122 define i8* @test7() nounwind {
124 %A = call noalias i8* @malloc(i64 4) nounwind
125 %tobool = icmp eq i8* %A, null
126 br i1 %tobool, label %return, label %if.end
133 %retval.0 = phi i8* [ %A, %if.end ], [ null, %entry ]
139 ; CHECK: define noalias i8* @test8(i32* %0)
140 define i8* @test8(i32* %0) nounwind uwtable {
141 %2 = tail call noalias i8* @malloc(i64 4)
142 %3 = icmp ne i32* %0, null
143 br i1 %3, label %4, label %5
154 ; Simple Argument Test
155 define internal void @test9(i8* %a, i8* %b) {
156 ; CHECK: define internal void @test9(i8* noalias nocapture readnone %a, i8* nocapture readnone %b)
159 define void @test9_helper(i8* %a, i8* %b) {
160 tail call void @test9(i8* noalias %a, i8* %b)
161 tail call void @test9(i8* noalias %b, i8* noalias %a)
167 ; Simple CallSite Test
169 declare void @test10_helper_1(i8* %a)
170 define void @test10_helper_2(i8* noalias %a) {
173 define void @test10(i8* noalias %a) {
174 ; CHECK: define void @test10(i8* noalias %a)
175 ; FIXME: missing noalias
176 ; CHECK-NEXT: tail call void @test10_helper_1(i8* %a)
177 tail call void @test10_helper_1(i8* %a)
179 ; CHECK-NEXT: tail call void @test10_helper_2(i8* noalias %a)
180 tail call void @test10_helper_2(i8* %a)
187 declare void @test11_helper(i8* %a, i8 *%b)
188 define void @test11(i8* noalias %a) {
189 ; CHECK: define void @test11(i8* noalias %a)
190 ; CHECK-NEXT: tail call void @test11_helper(i8* %a, i8* %a)
191 tail call void @test11_helper(i8* %a, i8* %a)
198 declare void @use_nocapture(i8* nocapture)
199 declare void @use(i8*)
200 define void @test12_1() {
201 ; CHECK-LABEL: @test12_1(
202 ; CHECK-NEXT: [[A:%.*]] = alloca i8, align 4
203 ; CHECK-NEXT: [[B:%.*]] = tail call noalias i8* @malloc(i64 4)
204 ; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nonnull align 4 dereferenceable(1) [[A]])
205 ; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nonnull align 4 dereferenceable(1) [[A]])
206 ; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nocapture [[B]])
207 ; CHECK-NEXT: tail call void @use_nocapture(i8* noalias [[B]])
208 ; CHECK-NEXT: ret void
210 %A = alloca i8, align 4
211 %B = tail call noalias i8* @malloc(i64 4)
212 tail call void @use_nocapture(i8* %A)
213 tail call void @use_nocapture(i8* %A)
214 tail call void @use_nocapture(i8* %B)
215 tail call void @use_nocapture(i8* %B)
219 define void @test12_2(){
220 ; CHECK-LABEL: @test12_2(
221 ; CHECK-NEXT: [[A:%.*]] = tail call noalias i8* @malloc(i64 4)
222 ; FIXME: This should be @use_nocapture(i8* noalias [[A]])
223 ; CHECK-NEXT: tail call void @use_nocapture(i8* nocapture [[A]])
224 ; FIXME: This should be @use_nocapture(i8* noalias [[A]])
225 ; CHECK-NEXT: tail call void @use_nocapture(i8* [[A]])
226 ; CHECK-NEXT: tail call void @use(i8* [[A]])
227 ; CHECK-NEXT: tail call void @use_nocapture(i8* [[A]])
228 ; CHECK-NEXT: ret void
230 %A = tail call noalias i8* @malloc(i64 4)
231 tail call void @use_nocapture(i8* %A)
232 tail call void @use_nocapture(i8* %A)
233 tail call void @use(i8* %A)
234 tail call void @use_nocapture(i8* %A)
238 declare void @two_args(i8* nocapture , i8* nocapture)
239 define void @test12_3(){
240 ; CHECK-LABEL: @test12_3(
241 %A = tail call noalias i8* @malloc(i64 4)
242 ; CHECK: tail call void @two_args(i8* nocapture %A, i8* %A)
243 tail call void @two_args(i8* %A, i8* %A)
247 define void @test12_4(){
248 ; CHECK-LABEL: @test12_4(
249 %A = tail call noalias i8* @malloc(i64 4)
250 %B = tail call noalias i8* @malloc(i64 4)
251 %A_0 = getelementptr i8, i8* %A, i64 0
252 %A_1 = getelementptr i8, i8* %A, i64 1
253 %B_0 = getelementptr i8, i8* %B, i64 0
255 ; CHECK: tail call void @two_args(i8* noalias %A, i8* noalias %B)
256 tail call void @two_args(i8* %A, i8* %B)
258 ; CHECK: tail call void @two_args(i8* %A, i8* nocapture %A_0)
259 tail call void @two_args(i8* %A, i8* %A_0)
261 ; CHECK: tail call void @two_args(i8* %A, i8* %A_1)
262 tail call void @two_args(i8* %A, i8* %A_1)
264 ; FIXME: This should be @two_args(i8* noalias %A_0, i8* noalias %B_0)
265 ; CHECK: tail call void @two_args(i8* %A_0, i8* nocapture %B_0)
266 tail call void @two_args(i8* %A_0, i8* %B_0)