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
|
; RUN: opt < %s -aa-pipeline=basic-aa -passes=aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
%struct.S = type { i32, [2 x i32], i32 }
%struct.S2 = type { i32, [4 x i32], [4 x i32] }
@G = global [10 x i32] zeroinitializer, align 4
; CHECK: Function: t1
; CHECK: NoAlias: i32* %gep1, i32* %gep2
define void @t1(ptr %s) {
%gep1 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 1
%gep2 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 0
load i32, ptr %gep1
load i32, ptr %gep2
ret void
}
; CHECK: Function: t2_fwd
; CHECK: MayAlias: i32* %gep1, i32* %gep2
define void @t2_fwd(ptr %s, ptr %q) {
%in_array = load i32, ptr %q, !range !0
%gep1 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 %in_array
%gep2 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 0
load i32, ptr %gep1
load i32, ptr %gep2
ret void
}
; CHECK: Function: t2_rev
; CHECK: MayAlias: i32* %gep1, i32* %gep2
define void @t2_rev(ptr %s, ptr %q) {
%in_array = load i32, ptr %q, !range !0
%gep1 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 0
%gep2 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 %in_array
load i32, ptr %gep1
load i32, ptr %gep2
ret void
}
; CHECK: Function: t3_fwd
; CHECK: NoAlias: i32* %gep1, i32* %gep2
define void @t3_fwd(ptr %s, ptr %q) {
%knownzero = load i32, ptr %q, !range !1
%gep1 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 %knownzero
%gep2 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 1
load i32, ptr %gep1
load i32, ptr %gep2
ret void
}
; CHECK: Function: t3_rev
; CHECK: NoAlias: i32* %gep1, i32* %gep2
define void @t3_rev(ptr %s, ptr %q) {
%knownzero = load i32, ptr %q, !range !1
%gep1 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 1
%gep2 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 %knownzero
load i32, ptr %gep1
load i32, ptr %gep2
ret void
}
; CHECK: Function: member_after
; CHECK: NoAlias: i32* %gep1, i32* %gep2
define void @member_after(ptr %s, ptr %q) {
%in_array = load i32, ptr %q, !range !0
%gep1 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 %in_array
%gep2 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 2
load i32, ptr %gep1
load i32, ptr %gep2
ret void
}
; CHECK: Function: member_after_rev
; CHECK: NoAlias: i32* %gep1, i32* %gep2
define void @member_after_rev(ptr %s, ptr %q) {
%in_array = load i32, ptr %q, !range !0
%gep2 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 2
%gep1 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 %in_array
load i32, ptr %gep1
load i32, ptr %gep2
ret void
}
; CHECK: Function: member_before
; CHECK: NoAlias: i32* %gep1, i32* %s
define void @member_before(ptr %s, ptr %q) {
%in_array = load i32, ptr %q, !range !0
%gep1 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 %in_array
load i32, ptr %gep1
load i32, ptr %s
ret void
}
; CHECK: Function: member_before_rev
; CHECK: NoAlias: i32* %gep1, i32* %s
define void @member_before_rev(ptr %s, ptr %q) {
%in_array = load i32, ptr %q, !range !0
%gep1 = getelementptr inbounds %struct.S, ptr %s, i64 0, i32 1, i32 %in_array
load i32, ptr %gep1
load i32, ptr %s
ret void
}
; CHECK-LABEL: Function: t5
; CHECK: MayAlias: i32* %gep1, %struct.S2* %s
; CHECK: PartialAlias (off -4): i32* %gep2, %struct.S2* %s
; CHECK: NoAlias: i32* %gep1, i32* %gep2
define void @t5(ptr %s, ptr %q) {
%in_array = load i32, ptr %q, !range !3
%gep1 = getelementptr inbounds %struct.S2, ptr %s, i64 0, i32 2, i32 %in_array
%gep2 = getelementptr inbounds %struct.S2, ptr %s, i64 0, i32 1, i32 0
load %struct.S2, ptr %s
load i32, ptr %gep1
load i32, ptr %gep2
ret void
}
; CHECK-LABEL: Function: t6
; CHECK: MayAlias: i32* %gep1, %struct.S2* %s
; CHECK: PartialAlias (off -16): i32* %gep2, %struct.S2* %s
; CHECK: MayAlias: i32* %gep1, i32* %gep2
define void @t6(ptr %s, ptr %q) {
%in_array = load i32, ptr %q, !range !3
%gep1 = getelementptr inbounds %struct.S2, ptr %s, i64 0, i32 2, i32 %in_array
%gep2 = getelementptr inbounds %struct.S2, ptr %s, i64 0, i32 1, i32 3
load %struct.S2, ptr %s
load i32, ptr %gep1
load i32, ptr %gep2
ret void
}
; CHECK-LABEL: Function: t7
; CHECK: MayAlias: i32* %gep1, %struct.S2* %s
; CHECK: PartialAlias (off -20): i32* %gep2, %struct.S2* %s
; CHECK: NoAlias: i32* %gep1, i32* %gep2
define void @t7(ptr %s, ptr %q) {
%in_array = load i32, ptr %q, !range !4
%gep1 = getelementptr inbounds %struct.S2, ptr %s, i64 0, i32 2, i32 %in_array
%gep2 = getelementptr inbounds %struct.S2, ptr %s, i64 0, i32 2, i32 0
load %struct.S2, ptr %s
load i32, ptr %gep1
load i32, ptr %gep2
ret void
}
; CHECK-LABEL: Function: t8
; CHECK: MayAlias: i32* %gep1, %struct.S2* %s
; CHECK: PartialAlias (off -24): i32* %gep2, %struct.S2* %s
; CHECK: MayAlias: i32* %gep1, i32* %gep2
define void @t8(ptr %s, ptr %q) {
%in_array = load i32, ptr %q, !range !4
%gep1 = getelementptr inbounds %struct.S2, ptr %s, i64 0, i32 2, i32 %in_array
%gep2 = getelementptr inbounds %struct.S2, ptr %s, i64 0, i32 2, i32 1
load %struct.S2, ptr %s
load i32, ptr %q
load i32, ptr %gep1
load i32, ptr %gep2
ret void
}
; CHECK-LABEL: Function: t9
; CHECK: MayAlias: i32* %gep1, %struct.S2* %s
; CHECK: PartialAlias (off -20): i32* %gep2, %struct.S2* %s
; CHECK: NoAlias: i32* %gep1, i32* %gep2
define void @t9(ptr %s, ptr %q) {
%in_array = load i32, ptr %q, !range !5
%gep1 = getelementptr inbounds %struct.S2, ptr %s, i64 0, i32 1, i32 %in_array
%gep2 = getelementptr inbounds %struct.S2, ptr %s, i64 0, i32 2, i32 0
load %struct.S2, ptr %s
load i32, ptr %gep1
load i32, ptr %gep2
ret void
}
; CHECK-LABEL: Function: t10
; CHECK: MayAlias: i32* %gep1, %struct.S2* %s
; CHECK: PartialAlias (off -4): i32* %gep2, %struct.S2* %s
; CHECK: MayAlias: i32* %gep1, i32* %gep2
define void @t10(ptr %s, ptr %q) {
%in_array = load i32, ptr %q, !range !5
%gep1 = getelementptr inbounds %struct.S2, ptr %s, i64 0, i32 2, i32 %in_array
%gep2 = getelementptr inbounds %struct.S2, ptr %s, i64 0, i32 1, i32 0
load %struct.S2, ptr %s
load i32, ptr %gep1
load i32, ptr %gep2
ret void
}
; CHECK-LABEL: Function: zeroext_index
; CHECK: MayAlias: i32* %gep, [256 x i32]* %s
define void @zeroext_index(ptr %s, ptr %q) {
%a = load i8, ptr %q, !range !6
%in_array = zext i8 %a to i32
%gep = getelementptr inbounds [256 x i32], ptr %s, i64 0, i32 %in_array
load [256 x i32], ptr %s
load i32, ptr %gep
ret void
}
; CHECK-LABEL: Function: multiple
; CHECK: MayAlias: i32* %p, i32* %p.01
; CHECK: MayAlias: i32* %p, i32* %p.02
; CHECK: MayAlias: i32* %p.01, i32* %p.02
; CHECK: NoAlias: i32* %p.01, i32* %p.2
; CHECK: MayAlias: i32* %p.02, i32* %p.2
; CHECK: NoAlias: i32* %p.01, i32* %p.3
; CHECK: NoAlias: i32* %p.02, i32* %p.3
define void @multiple(ptr %p, ptr %o1_ptr, ptr %o2_ptr) {
%o1 = load i32, ptr %o1_ptr, !range !0
%o2 = load i32, ptr %o2_ptr, !range !0
%p.01 = getelementptr i32, ptr %p, i32 %o1 ; p + [0, 1]
%p.02 = getelementptr i32, ptr %p.01, i32 %o2 ; p + [0, 2]
%p.2 = getelementptr i32, ptr %p, i32 2
%p.3 = getelementptr i32, ptr %p, i32 3
load i32, ptr %p
load i32, ptr %p.01
load i32, ptr %p.02
load i32, ptr %p.2
load i32, ptr %p.3
ret void
}
; p.neg1 and p.o.1 don't alias, even though the addition o+1 may overflow.
; While it makes INT_MIN a possible offset, offset -1 is not possible.
; CHECK-LABEL: Function: benign_overflow
; CHECK: MayAlias: i8* %p, i8* %p.o
; CHECK: MayAlias: i8* %p.neg1, i8* %p.o
; CHECK: MayAlias: i8* %p, i8* %p.o.1
; CHECK: NoAlias: i8* %p.neg1, i8* %p.o.1
; CHECK: NoAlias: i8* %p.o, i8* %p.o.1
define void @benign_overflow(ptr %p, i64 %o) {
%c = icmp sge i64 %o, -1
call void @llvm.assume(i1 %c)
%p.neg1 = getelementptr i8, ptr %p, i64 -1
%p.o = getelementptr i8, ptr %p, i64 %o
%p.o.1 = getelementptr i8, ptr %p.o, i64 1
load i8, ptr %p
load i8, ptr %p.neg1
load i8, ptr %p.o
load i8, ptr %p.o.1
ret void
}
; CHECK-LABEL: pr63266
; CHECK: MayAlias: i8* %gep2, i8* %offset16
define void @pr63266(i1 %c, ptr %base) {
entry:
%offset16 = getelementptr inbounds i8, ptr %base, i64 16
%gep1 = getelementptr i8, ptr %base, i64 -9223372036854775792
br i1 %c, label %if, label %join
if:
br label %join
join:
%phi = phi i64 [ -9223372036854775808, %if ], [ 0, %entry ]
%gep2 = getelementptr i8, ptr %gep1, i64 %phi
store i8 0, ptr %gep2
load i8, ptr %offset16
ret void
}
; CHECK-LABEL: Function: select_in_gep
; CHECK: NoAlias: i32* %arrayidx, i32* getelementptr inbounds ([10 x i32], ptr @G, i64 0, i64 3)
define i32 @select_in_gep(i1 %c) {
entry:
%select_ = select i1 %c, i64 2, i64 1
%arrayidx = getelementptr inbounds [10 x i32], ptr @G, i64 0, i64 %select_
store i32 42, ptr %arrayidx, align 4
%load_ = load i32, ptr getelementptr inbounds ([10 x i32], ptr @G, i64 0, i64 3), align 4
ret i32 %load_
}
declare void @llvm.assume(i1)
!0 = !{ i32 0, i32 2 }
!1 = !{ i32 0, i32 1 }
!2 = !{ i32 1, i32 2 }
!3 = !{ i32 -2, i32 0 }
!4 = !{ i32 1, i32 536870911 }
!5 = !{ i32 -536870911, i32 4 }
!6 = !{ i8 -2, i8 0 }
|