noalias.ll
7.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=3 < %s | FileCheck %s
; TEST 1 - negative.
; void *G;
; void *foo(){
; void *V = malloc(4);
; G = V;
; return V;
; }
@G = external global i8*
; CHECK: define i8* @foo()
define i8* @foo() {
%1 = tail call noalias i8* @malloc(i64 4)
store i8* %1, i8** @G, align 8
ret i8* %1
}
declare noalias i8* @malloc(i64)
; TEST 2
; call noalias function in return instruction.
; CHECK: define noalias i8* @return_noalias()
define i8* @return_noalias(){
%1 = tail call noalias i8* @malloc(i64 4)
ret i8* %1
}
define void @nocapture(i8* %a){
ret void
}
; CHECK: define noalias i8* @return_noalias_looks_like_capture()
define i8* @return_noalias_looks_like_capture(){
%1 = tail call noalias i8* @malloc(i64 4)
call void @nocapture(i8* %1)
ret i8* %1
}
declare i8* @alias()
; TEST 3
; CHECK: define i8* @call_alias()
; CHECK-NOT: noalias
define i8* @call_alias(){
%1 = tail call i8* @alias()
ret i8* %1
}
; TEST 4
; void *baz();
; void *foo(int a);
;
; void *bar() {
; foo(0);
; return baz();
; }
;
; void *foo(int a) {
; if (a)
; bar();
; return malloc(4);
; }
; CHECK: define i8* @bar()
define i8* @bar() nounwind uwtable {
%1 = tail call i8* (...) @baz()
ret i8* %1
}
; CHECK: define noalias i8* @foo1(i32 %0)
define i8* @foo1(i32 %0) nounwind uwtable {
%2 = icmp eq i32 %0, 0
br i1 %2, label %5, label %3
3: ; preds = %1
%4 = tail call i8* (...) @baz()
br label %5
5: ; preds = %1, %3
%6 = tail call noalias i8* @malloc(i64 4)
ret i8* %6
}
declare i8* @baz(...) nounwind uwtable
; TEST 5
; Returning global pointer. Should not be noalias.
; CHECK: define nonnull align 8 dereferenceable(8) i8** @getter()
define i8** @getter() {
ret i8** @G
}
; Returning global pointer. Should not be noalias.
; CHECK: define nonnull align 8 dereferenceable(8) i8** @calle1()
define i8** @calle1(){
%1 = call i8** @getter()
ret i8** %1
}
; TEST 6
declare noalias i8* @strdup(i8* nocapture) nounwind
; CHECK: define noalias i8* @test6()
define i8* @test6() nounwind uwtable ssp {
%x = alloca [2 x i8], align 1
%arrayidx = getelementptr inbounds [2 x i8], [2 x i8]* %x, i64 0, i64 0
store i8 97, i8* %arrayidx, align 1
%arrayidx1 = getelementptr inbounds [2 x i8], [2 x i8]* %x, i64 0, i64 1
store i8 0, i8* %arrayidx1, align 1
%call = call noalias i8* @strdup(i8* %arrayidx) nounwind
ret i8* %call
}
; TEST 7
; CHECK: define noalias i8* @test7()
define i8* @test7() nounwind {
entry:
%A = call noalias i8* @malloc(i64 4) nounwind
%tobool = icmp eq i8* %A, null
br i1 %tobool, label %return, label %if.end
if.end:
store i8 7, i8* %A
br label %return
return:
%retval.0 = phi i8* [ %A, %if.end ], [ null, %entry ]
ret i8* %retval.0
}
; TEST 8
; CHECK: define noalias i8* @test8(i32* %0)
define i8* @test8(i32* %0) nounwind uwtable {
%2 = tail call noalias i8* @malloc(i64 4)
%3 = icmp ne i32* %0, null
br i1 %3, label %4, label %5
4: ; preds = %1
store i8 10, i8* %2
br label %5
5: ; preds = %1, %4
ret i8* %2
}
; TEST 9
; Simple Argument Test
declare void @use_i8(i8* nocapture) readnone
define internal void @test9a(i8* %a, i8* %b) {
; CHECK: define internal void @test9a()
ret void
}
define internal void @test9b(i8* %a, i8* %b) {
; CHECK: define internal void @test9b(i8* noalias nocapture readnone %a, i8* nocapture readnone %b)
call void @use_i8(i8* %a)
call void @use_i8(i8* %b)
ret void
}
define void @test9_helper(i8* %a, i8* %b) {
; CHECK: define void @test9_helper(i8* nocapture readnone %a, i8* nocapture readnone %b)
; CHECK: tail call void @test9a()
; CHECK: tail call void @test9a()
; CHECK: tail call void @test9b(i8* noalias nocapture readnone %a, i8* nocapture readnone %b)
; CHECK: tail call void @test9b(i8* noalias nocapture readnone %b, i8* noalias nocapture readnone %a)
tail call void @test9a(i8* noalias %a, i8* %b)
tail call void @test9a(i8* noalias %b, i8* noalias %a)
tail call void @test9b(i8* noalias %a, i8* %b)
tail call void @test9b(i8* noalias %b, i8* noalias %a)
ret void
}
; TEST 10
; Simple CallSite Test
declare void @test10_helper_1(i8* %a)
define void @test10_helper_2(i8* noalias %a) {
; CHECK: tail call void @test10_helper_1(i8* %a)
tail call void @test10_helper_1(i8* %a)
ret void
}
define void @test10(i8* noalias %a) {
; CHECK: define void @test10(i8* noalias %a)
; FIXME: missing noalias
; CHECK-NEXT: tail call void @test10_helper_1(i8* %a)
tail call void @test10_helper_1(i8* %a)
; CHECK-NEXT: tail call void @test10_helper_2(i8* noalias %a)
tail call void @test10_helper_2(i8* %a)
ret void
}
; TEST 11
; CallSite Test
declare void @test11_helper(i8* %a, i8 *%b)
define void @test11(i8* noalias %a) {
; CHECK: define void @test11(i8* noalias %a)
; CHECK-NEXT: tail call void @test11_helper(i8* %a, i8* %a)
tail call void @test11_helper(i8* %a, i8* %a)
ret void
}
; TEST 12
; CallSite Argument
declare void @use_nocapture(i8* nocapture)
declare void @use(i8*)
define void @test12_1() {
; CHECK-LABEL: @test12_1(
; CHECK-NEXT: [[A:%.*]] = alloca i8, align 4
; CHECK-NEXT: [[B:%.*]] = tail call noalias i8* @malloc(i64 4)
; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nonnull align 4 dereferenceable(1) [[A]])
; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nonnull align 4 dereferenceable(1) [[A]])
; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nocapture [[B]])
; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nocapture [[B]])
; CHECK-NEXT: ret void
;
%A = alloca i8, align 4
%B = tail call noalias i8* @malloc(i64 4)
tail call void @use_nocapture(i8* %A)
tail call void @use_nocapture(i8* %A)
tail call void @use_nocapture(i8* %B)
tail call void @use_nocapture(i8* %B)
ret void
}
define void @test12_2(){
; CHECK-LABEL: @test12_2(
; CHECK-NEXT: [[A:%.*]] = tail call noalias i8* @malloc(i64 4)
; FIXME: This should be @use_nocapture(i8* noalias [[A]])
; CHECK-NEXT: tail call void @use_nocapture(i8* nocapture [[A]])
; FIXME: This should be @use_nocapture(i8* noalias nocapture [[A]])
; CHECK-NEXT: tail call void @use_nocapture(i8* nocapture [[A]])
; CHECK-NEXT: tail call void @use(i8* [[A]])
; CHECK-NEXT: tail call void @use_nocapture(i8* nocapture [[A]])
; CHECK-NEXT: ret void
;
%A = tail call noalias i8* @malloc(i64 4)
tail call void @use_nocapture(i8* %A)
tail call void @use_nocapture(i8* %A)
tail call void @use(i8* %A)
tail call void @use_nocapture(i8* %A)
ret void
}
declare void @two_args(i8* nocapture , i8* nocapture)
define void @test12_3(){
; CHECK-LABEL: @test12_3(
%A = tail call noalias i8* @malloc(i64 4)
; CHECK: tail call void @two_args(i8* nocapture %A, i8* nocapture %A)
tail call void @two_args(i8* %A, i8* %A)
ret void
}
define void @test12_4(){
; CHECK-LABEL: @test12_4(
%A = tail call noalias i8* @malloc(i64 4)
%B = tail call noalias i8* @malloc(i64 4)
%A_0 = getelementptr i8, i8* %A, i64 0
%A_1 = getelementptr i8, i8* %A, i64 1
%B_0 = getelementptr i8, i8* %B, i64 0
; CHECK: tail call void @two_args(i8* noalias nocapture %A, i8* noalias nocapture %B)
tail call void @two_args(i8* %A, i8* %B)
; CHECK: tail call void @two_args(i8* nocapture %A, i8* nocapture %A_0)
tail call void @two_args(i8* %A, i8* %A_0)
; CHECK: tail call void @two_args(i8* nocapture %A, i8* nocapture %A_1)
tail call void @two_args(i8* %A, i8* %A_1)
; FIXME: This should be @two_args(i8* noalias nocapture %A_0, i8* noalias nocapture %B_0)
; CHECK: tail call void @two_args(i8* nocapture %A_0, i8* nocapture %B_0)
tail call void @two_args(i8* %A_0, i8* %B_0)
ret void
}