base_pointer.ll
7.6 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
285
286
287
288
289
290
291
292
293
294
295
296
; RUN: opt %loadPolly -disable-basic-aa -polly-detect -polly-invariant-load-hoisting=true -analyze < %s | FileCheck %s
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
define void @base_pointer_in_condition(i64** noalias %A_ptr, i64 %N) nounwind {
entry:
fence seq_cst
br label %pre
pre:
%A = load i64*, i64** %A_ptr
br i1 true, label %for.i, label %then
for.i:
%indvar = phi i64 [ 0, %pre ], [ %indvar.next, %for.i ]
%scevgep = getelementptr i64, i64* %A, i64 %indvar
store i64 %indvar, i64* %scevgep
%indvar.next = add nsw i64 %indvar, 1
%exitcond = icmp eq i64 %indvar.next, %N
br i1 %exitcond, label %then, label %for.i
then:
br label %return
return:
fence seq_cst
ret void
}
; CHECK-LABEL: base_pointer_in_condition
; CHECK: Valid Region for Scop: pre => return
define void @base_pointer_is_argument(float* %A, i64 %n) {
entry:
br label %for.i
for.i:
%indvar.i = phi i64 [ %indvar.i.next, %for.i.inc ], [ 0, %entry ]
br label %S1
S1:
%conv = sitofp i64 %indvar.i to float
%arrayidx5 = getelementptr float, float* %A, i64 %indvar.i
store float %conv, float* %arrayidx5, align 4
br label %for.i.inc
for.i.inc:
%indvar.i.next = add i64 %indvar.i, 1
%exitcond.i = icmp ne i64 %indvar.i.next, %n
br i1 %exitcond.i, label %for.i, label %exit
exit:
ret void
}
; CHECK-LABEL: base_pointer_is_argument
; CHECK: Valid Region for Scop: for.i => exit
define void @base_pointer_is_const_expr(i64 %n) {
entry:
br label %for.i
for.i:
%indvar.i = phi i64 [ %indvar.i.next, %for.i.inc ], [ 0, %entry ]
br label %S1
S1:
%conv = sitofp i64 %indvar.i to float
%arrayidx5 = getelementptr float, float* inttoptr (i64 100 to float*), i64 %indvar.i
store float %conv, float* %arrayidx5, align 4
br label %for.i.inc
for.i.inc:
%indvar.i.next = add i64 %indvar.i, 1
%exitcond.i = icmp ne i64 %indvar.i.next, %n
br i1 %exitcond.i, label %for.i, label %exit
exit:
ret void
}
; CHECK-LABEL: base_pointer_is_const_expr
; CHECK-LABEL: Valid Region for Scop: for.i => exit
@A = external global float
define void @base_pointer_is_global(i64 %n) {
entry:
br label %for.i
for.i:
%indvar.i = phi i64 [ %indvar.i.next, %for.i.inc ], [ 0, %entry ]
br label %S1
S1:
%conv = sitofp i64 %indvar.i to float
%arrayidx5 = getelementptr float, float* @A, i64 %indvar.i
store float %conv, float* %arrayidx5, align 4
br label %for.i.inc
for.i.inc:
%indvar.i.next = add i64 %indvar.i, 1
%exitcond.i = icmp ne i64 %indvar.i.next, %n
br i1 %exitcond.i, label %for.i, label %exit
exit:
ret void
}
; CHECK-LABEL: base_pointer_is_global
; CHECK: Valid Region for Scop: for.i => exit
declare float *@foo()
define void @base_pointer_is_inst_outside(i64 %n) {
entry:
%A = call float *@foo()
br label %for.i
for.i:
%indvar.i = phi i64 [ %indvar.i.next, %for.i.inc ], [ 0, %entry ]
br label %S1
S1:
%conv = sitofp i64 %indvar.i to float
%arrayidx5 = getelementptr float, float* %A, i64 %indvar.i
store float %conv, float* %arrayidx5, align 4
br label %for.i.inc
for.i.inc:
%indvar.i.next = add i64 %indvar.i, 1
%exitcond.i = icmp ne i64 %indvar.i.next, %n
br i1 %exitcond.i, label %for.i, label %exit
exit:
ret void
}
; CHECK-LABEL: base_pointer_is_inst_outside
; CHECK: Valid Region for Scop: for.i => exit
declare float* @getNextBasePtr(float*) readnone nounwind
define void @base_pointer_is_phi_node(i64 %n, float* %A) {
entry:
br label %for.i
for.i:
%indvar.i = phi i64 [ %indvar.i.next, %for.i.inc ], [ 0, %entry ]
%ptr = phi float* [ %ptr.next, %for.i.inc ], [ %A, %entry ]
; To get a PHI node inside a SCoP that can not be analyzed but
; for which the surrounding SCoP is normally still valid we use a function
; without any side effects.
%ptr.next = call float* @getNextBasePtr(float* %ptr)
br label %S1
S1:
%conv = sitofp i64 %indvar.i to float
%arrayidx5 = getelementptr float, float* %ptr, i64 %indvar.i
store float %conv, float* %arrayidx5, align 4
br label %for.i.inc
for.i.inc:
%indvar.i.next = add i64 %indvar.i, 1
%exitcond.i = icmp ne i64 %indvar.i.next, %n
br i1 %exitcond.i, label %for.i, label %exit
exit:
ret void
}
; CHECK-LABEL: base_pointer_is_phi_node
; CHECK-NOT: Valid Region for Scop
define void @base_pointer_is_inst_inside_invariant_1(i64 %n, float* %A) {
entry:
br label %for.i
for.i:
%indvar.i = phi i64 [ %indvar.i.next, %for.i.inc ], [ 0, %entry ]
; A function return value, even with readnone nounwind attributes, is not
; considered a valid base pointer because it can return a pointer that aliases
; with something else (e.g. %A or a global) or return a different pointer at
; every call (e.g. malloc)
%ptr = call float* @getNextBasePtr(float* %A)
br label %S1
S1:
%conv = sitofp i64 %indvar.i to float
%arrayidx5 = getelementptr float, float* %ptr, i64 %indvar.i
store float %conv, float* %arrayidx5, align 4
br label %for.i.inc
for.i.inc:
%indvar.i.next = add i64 %indvar.i, 1
%exitcond.i = icmp ne i64 %indvar.i.next, %n
br i1 %exitcond.i, label %for.i, label %exit
exit:
ret void
}
; CHECK-LABEL: base_pointer_is_inst_inside_invariant_1
; CHECK-NOT: Valid Region for Scop
declare float* @getNextBasePtr2(float*) readnone nounwind
define void @base_pointer_is_inst_inside_invariant_2(i64 %n, float* %A) {
entry:
br label %for.i
for.i:
%indvar.i = phi i64 [ %indvar.i.next, %for.i.inc ], [ 0, %entry ]
%ptr = call float* @getNextBasePtr2(float* %A)
%ptr2 = call float* @getNextBasePtr(float* %ptr)
br label %S1
S1:
%conv = sitofp i64 %indvar.i to float
%arrayidx5 = getelementptr float, float* %ptr2, i64 %indvar.i
store float %conv, float* %arrayidx5, align 4
br label %for.i.inc
for.i.inc:
%indvar.i.next = add i64 %indvar.i, 1
%exitcond.i = icmp ne i64 %indvar.i.next, %n
br i1 %exitcond.i, label %for.i, label %exit
exit:
ret void
}
; CHECK-LABEL: base_pointer_is_inst_inside_invariant_2
; CHECK-NOT: Valid Region for Scop
declare float* @getNextBasePtr3(float*, i64) readnone nounwind
define void @base_pointer_is_inst_inside_variant(i64 %n, float* %A) {
entry:
br label %for.i
for.i:
%indvar.i = phi i64 [ %indvar.i.next, %for.i.inc ], [ 0, %entry ]
%ptr = call float* @getNextBasePtr3(float* %A, i64 %indvar.i)
%ptr2 = call float* @getNextBasePtr(float* %ptr)
br label %S1
S1:
%conv = sitofp i64 %indvar.i to float
%arrayidx5 = getelementptr float, float* %ptr2, i64 %indvar.i
store float %conv, float* %arrayidx5, align 4
br label %for.i.inc
for.i.inc:
%indvar.i.next = add i64 %indvar.i, 1
%exitcond.i = icmp ne i64 %indvar.i.next, %n
br i1 %exitcond.i, label %for.i, label %exit
exit:
ret void
}
; CHECK: base_pointer_is_inst_inside_variant
; CHECK-NOT: Valid Region for Scop
define void @base_pointer_is_ptr2ptr(float** noalias %A, i64 %n) {
entry:
br label %for.i
for.i:
%indvar.i = phi i64 [ %indvar.i.next, %for.i.inc ], [ 0, %entry ]
%arrayidx = getelementptr float*, float** %A, i64 %indvar.i
br label %for.j
for.j:
%indvar.j = phi i64 [ 0, %for.i ], [ %indvar.j.next, %for.j ]
%conv = sitofp i64 %indvar.i to float
%basepointer = load float*, float** %arrayidx, align 8
%arrayidx5 = getelementptr float, float* %basepointer, i64 %indvar.j
store float %conv, float* %arrayidx5, align 4
%indvar.j.next = add i64 %indvar.j, 1
%exitcond.j = icmp ne i64 %indvar.j.next, %n
br i1 %exitcond.j, label %for.j, label %for.i.inc
for.i.inc:
%indvar.i.next = add i64 %indvar.i, 1
%exitcond.i = icmp ne i64 %indvar.i.next, %n
br i1 %exitcond.i, label %for.i, label %exit
exit:
ret void
}
; CHECK: base_pointer_is_ptr2ptr
; CHECK: Valid Region for Scop: for.j => for.i.inc