/
loads.ll
414 lines (357 loc) · 11.2 KB
/
loads.ll
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -data-layout="e-p:64:64:64-p1:16:16:16-p2: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-ni:2" -passes=instsimplify -S | FileCheck %s --check-prefixes=CHECK,LE
; RUN: opt < %s -data-layout="E-p:64:64:64-p1:16:16:16-p2: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-ni:2" -passes=instsimplify -S | FileCheck %s --check-prefixes=CHECK,BE
; {{ 0xDEADBEEF, 0xBA }, 0xCAFEBABE}
@g1 = constant {{i32,i8},i32} {{i32,i8} { i32 -559038737, i8 186 }, i32 -889275714 }
@g2 = constant double 1.0
; { 0x7B, 0x06B1BFF8 }
@g3 = constant {i64, i64} { i64 123, i64 112312312 }
; Simple load
define i32 @test1() {
; CHECK-LABEL: @test1(
; CHECK-NEXT: ret i32 -559038737
;
%r = load i32, i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0)
ret i32 %r
}
; PR3152
; Load of first 16 bits of 32-bit value.
define i16 @test2() {
; LE-LABEL: @test2(
; LE-NEXT: ret i16 -16657
;
; BE-LABEL: @test2(
; BE-NEXT: ret i16 -8531
;
%r = load i16, i16* bitcast(i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*)
ret i16 %r
}
define i16 @test2_addrspacecast() {
; LE-LABEL: @test2_addrspacecast(
; LE-NEXT: ret i16 -16657
;
; BE-LABEL: @test2_addrspacecast(
; BE-NEXT: ret i16 -8531
;
%r = load i16, i16 addrspace(1)* addrspacecast(i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16 addrspace(1)*)
ret i16 %r
}
; Load of second 16 bits of 32-bit value.
define i16 @test3() {
; LE-LABEL: @test3(
; LE-NEXT: ret i16 -8531
;
; BE-LABEL: @test3(
; BE-NEXT: ret i16 -16657
;
%r = load i16, i16* getelementptr(i16, i16* bitcast(i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*), i32 1)
ret i16 %r
}
; Load of 8 bit field + tail padding.
define i16 @test4() {
; LE-LABEL: @test4(
; LE-NEXT: ret i16 186
;
; BE-LABEL: @test4(
; BE-NEXT: ret i16 -17920
;
%r = load i16, i16* getelementptr(i16, i16* bitcast(i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*), i32 2)
ret i16 %r
}
; Load of double bits.
define i64 @test6() {
; CHECK-LABEL: @test6(
; CHECK-NEXT: ret i64 4607182418800017408
;
%r = load i64, i64* bitcast(double* @g2 to i64*)
ret i64 %r
}
; Load of double bits.
define i16 @test7() {
; LE-LABEL: @test7(
; LE-NEXT: ret i16 0
;
; BE-LABEL: @test7(
; BE-NEXT: ret i16 16368
;
%r = load i16, i16* bitcast(double* @g2 to i16*)
ret i16 %r
}
; Double load.
define double @test8() {
; LE-LABEL: @test8(
; LE-NEXT: ret double 0xBADEADBEEF
;
; BE-LABEL: @test8(
; BE-NEXT: ret double 0xDEADBEEFBA000000
;
%r = load double, double* bitcast({{i32,i8},i32}* @g1 to double*)
ret double %r
}
; i128 load.
define i128 @test_i128() {
; LE-LABEL: @test_i128(
; LE-NEXT: ret i128 2071796475790618158476296315
;
; BE-LABEL: @test_i128(
; BE-NEXT: ret i128 2268949521066387161080
;
%r = load i128, i128* bitcast({i64, i64}* @g3 to i128*)
ret i128 %r
}
define fp128 @test_fp128() {
; LE-LABEL: @test_fp128(
; LE-NEXT: ret fp128 0xL000000000000007B0000000006B1BFF8
;
; BE-LABEL: @test_fp128(
; BE-NEXT: ret fp128 0xL0000000006B1BFF8000000000000007B
;
%r = load fp128, fp128* bitcast({i64, i64}* @g3 to fp128*)
ret fp128 %r
}
define ppc_fp128 @test_ppc_fp128() {
; LE-LABEL: @test_ppc_fp128(
; LE-NEXT: ret ppc_fp128 bitcast (i128 2071796475790618158476296315 to ppc_fp128)
;
; BE-LABEL: @test_ppc_fp128(
; BE-NEXT: ret ppc_fp128 bitcast (i128 2268949521066387161080 to ppc_fp128)
;
%r = load ppc_fp128, ppc_fp128* bitcast({i64, i64}* @g3 to ppc_fp128*)
ret ppc_fp128 %r
}
define x86_fp80 @test_x86_fp80() {
; LE-LABEL: @test_x86_fp80(
; LE-NEXT: ret x86_fp80 0xKFFFF000000000000007B
;
; BE-LABEL: @test_x86_fp80(
; BE-NEXT: ret x86_fp80 0xK000000000000007B0000
;
%r = load x86_fp80, x86_fp80* bitcast({i64, i64}* @g3 to x86_fp80*)
ret x86_fp80 %r
}
define bfloat @test_bfloat() {
; LE-LABEL: @test_bfloat(
; LE-NEXT: ret bfloat 0xR007B
;
; BE-LABEL: @test_bfloat(
; BE-NEXT: ret bfloat 0xR0000
;
%r = load bfloat, bfloat* bitcast({i64, i64}* @g3 to bfloat*)
ret bfloat %r
}
; vector load.
define <2 x i64> @test10() {
; CHECK-LABEL: @test10(
; CHECK-NEXT: ret <2 x i64> <i64 123, i64 112312312>
;
%r = load <2 x i64>, <2 x i64>* bitcast({i64, i64}* @g3 to <2 x i64>*)
ret <2 x i64> %r
}
; PR5287
; { 0xA1, 0x08 }
@g4 = internal constant { i8, i8 } { i8 -95, i8 8 }
define i16 @test11() nounwind {
; LE-LABEL: @test11(
; LE-NEXT: entry:
; LE-NEXT: ret i16 2209
;
; BE-LABEL: @test11(
; BE-NEXT: entry:
; BE-NEXT: ret i16 -24312
;
entry:
%a = load i16, i16* bitcast ({ i8, i8 }* @g4 to i16*)
ret i16 %a
}
; PR5551
@test12g = private constant [6 x i8] c"a\00b\00\00\00"
define i16 @test12() {
; LE-LABEL: @test12(
; LE-NEXT: ret i16 98
;
; BE-LABEL: @test12(
; BE-NEXT: ret i16 25088
;
%a = load i16, i16* getelementptr inbounds ([3 x i16], [3 x i16]* bitcast ([6 x i8]* @test12g to [3 x i16]*), i32 0, i64 1)
ret i16 %a
}
; PR5978
@g5 = constant i8 4
define i1 @test13() {
; CHECK-LABEL: @test13(
; CHECK-NEXT: ret i1 false
;
%A = load i1, i1* bitcast (i8* @g5 to i1*)
ret i1 %A
}
@g6 = constant [2 x i8*] [i8* inttoptr (i64 1 to i8*), i8* inttoptr (i64 2 to i8*)]
define i64 @test14() nounwind {
; CHECK-LABEL: @test14(
; CHECK-NEXT: entry:
; CHECK-NEXT: ret i64 1
;
entry:
%tmp = load i64, i64* bitcast ([2 x i8*]* @g6 to i64*)
ret i64 %tmp
}
; Check with address space pointers
@g6_as1 = constant [2 x i8 addrspace(1)*] [i8 addrspace(1)* inttoptr (i16 1 to i8 addrspace(1)*), i8 addrspace(1)* inttoptr (i16 2 to i8 addrspace(1)*)]
define i16 @test14_as1() nounwind {
; CHECK-LABEL: @test14_as1(
; CHECK-NEXT: entry:
; CHECK-NEXT: ret i16 1
;
entry:
%tmp = load i16, i16* bitcast ([2 x i8 addrspace(1)*]* @g6_as1 to i16*)
ret i16 %tmp
}
define i64 @test15() nounwind {
; CHECK-LABEL: @test15(
; CHECK-NEXT: entry:
; CHECK-NEXT: ret i64 2
;
entry:
%tmp = load i64, i64* bitcast (i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @g6, i32 0, i64 1) to i64*)
ret i64 %tmp
}
@gv7 = constant [4 x i8*] [i8* null, i8* inttoptr (i64 -14 to i8*), i8* null, i8* null]
define i64 @test16.1() {
; CHECK-LABEL: @test16.1(
; CHECK-NEXT: ret i64 0
;
%v = load i64, i64* bitcast ([4 x i8*]* @gv7 to i64*), align 8
ret i64 %v
}
define i64 @test16.2() {
; CHECK-LABEL: @test16.2(
; CHECK-NEXT: ret i64 -14
;
%v = load i64, i64* bitcast (i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @gv7, i64 0, i64 1) to i64*), align 8
ret i64 %v
}
define i64 @test16.3() {
; CHECK-LABEL: @test16.3(
; CHECK-NEXT: ret i64 0
;
%v = load i64, i64* bitcast (i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @gv7, i64 0, i64 2) to i64*), align 8
ret i64 %v
}
@g7 = constant {[0 x i32], [0 x i8], {}*} { [0 x i32] undef, [0 x i8] undef, {}* null }
define i64* @test_leading_zero_size_elems() {
; CHECK-LABEL: @test_leading_zero_size_elems(
; CHECK-NEXT: ret i64* null
;
%v = load i64*, i64** bitcast ({[0 x i32], [0 x i8], {}*}* @g7 to i64**)
ret i64* %v
}
@g8 = constant {[4294967295 x [0 x i32]], i64} { [4294967295 x [0 x i32]] undef, i64 123 }
define i64 @test_leading_zero_size_elems_big() {
; CHECK-LABEL: @test_leading_zero_size_elems_big(
; CHECK-NEXT: ret i64 123
;
%v = load i64, i64* bitcast ({[4294967295 x [0 x i32]], i64}* @g8 to i64*)
ret i64 %v
}
@g9 = constant [4294967295 x [0 x i32]] zeroinitializer
define i64 @test_array_of_zero_size_array() {
; CHECK-LABEL: @test_array_of_zero_size_array(
; CHECK-NEXT: ret i64 undef
;
%v = load i64, i64* bitcast ([4294967295 x [0 x i32]]* @g9 to i64*)
ret i64 %v
}
@g_undef = constant { i128 } undef
define i32* @test_undef_aggregate() {
; CHECK-LABEL: @test_undef_aggregate(
; CHECK-NEXT: ret i32* undef
;
%v = load i32*, i32** bitcast ({i128}* @g_undef to i32**)
ret i32* %v
}
@g_poison = constant { i128 } poison
define i32* @test_poison_aggregate() {
; CHECK-LABEL: @test_poison_aggregate(
; CHECK-NEXT: ret i32* poison
;
%v = load i32*, i32** bitcast ({i128}* @g_poison to i32**)
ret i32* %v
}
@g11 = constant <{ [8 x i8], [8 x i8] }> <{ [8 x i8] undef, [8 x i8] zeroinitializer }>, align 4
define {}* @test_trailing_zero_gep_index() {
; CHECK-LABEL: @test_trailing_zero_gep_index(
; CHECK-NEXT: ret {}* null
;
%v = load {}*, {}** bitcast (i8* getelementptr inbounds (<{ [8 x i8], [8 x i8] }>, <{ [8 x i8], [8 x i8] }>* @g11, i32 0, i32 1, i32 0) to {}**), align 4
ret {}* %v
}
define { i64, i64 } @test_load_struct() {
; CHECK-LABEL: @test_load_struct(
; CHECK-NEXT: ret { i64, i64 } { i64 123, i64 112312312 }
;
%v = load { i64, i64 }, { i64, i64 }* @g3
ret { i64, i64 } %v
}
@m64 = internal constant [2 x i64] zeroinitializer
@idx = external global i32
; This should not try to create an x86_mmx null value.
define x86_mmx @load_mmx() {
; CHECK-LABEL: @load_mmx(
; CHECK-NEXT: [[TEMP:%.*]] = load x86_mmx, x86_mmx* bitcast (i64* getelementptr ([2 x i64], [2 x i64]* @m64, i64 0, i64 ptrtoint (i32* @idx to i64)) to x86_mmx*), align 8
; CHECK-NEXT: ret x86_mmx [[TEMP]]
;
%temp = load x86_mmx, x86_mmx* bitcast (i64* getelementptr ([2 x i64], [2 x i64]* @m64, i64 0, i64 ptrtoint (i32* @idx to i64)) to x86_mmx*)
ret x86_mmx %temp
}
@g_offset = external global i64
@g_neg_one_vec = constant <4 x i8> <i8 -1, i8 -1, i8 -1, i8 -1>
define i8 @load_neg_one_at_unknown_offset() {
; CHECK-LABEL: @load_neg_one_at_unknown_offset(
; CHECK-NEXT: ret i8 -1
;
%v = load i8, i8* getelementptr (<4 x i8>, <4 x i8>* @g_neg_one_vec, i64 0, i64 ptrtoint (i64* @g_offset to i64))
ret i8 %v
}
@g_with_padding = constant { i32, [4 x i8] } { i32 0, [4 x i8] undef }
define i32 @load_padding() {
; CHECK-LABEL: @load_padding(
; CHECK-NEXT: ret i32 undef
;
%v = load i32, i32* getelementptr (i32, i32* bitcast ({ i32, [4 x i8] }* @g_with_padding to i32*), i64 1)
ret i32 %v
}
@g_all_undef = constant { i32, [4 x i8] } undef
; Same as the previous case, but with an all-undef initializer.
define i32 @load_all_undef() {
; CHECK-LABEL: @load_all_undef(
; CHECK-NEXT: ret i32 undef
;
%v = load i32, i32* getelementptr (i32, i32* bitcast ({ i32, [4 x i8] }* @g_all_undef to i32*), i64 1)
ret i32 %v
}
@g_i8_data = constant [16 x i8] c"\01\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
define i64* @load_ptr_from_i8_data() {
; LE-LABEL: @load_ptr_from_i8_data(
; LE-NEXT: ret i64* inttoptr (i64 1 to i64*)
;
; BE-LABEL: @load_ptr_from_i8_data(
; BE-NEXT: ret i64* inttoptr (i64 72057594037927936 to i64*)
;
%v = load i64*, i64** bitcast ([16 x i8]* @g_i8_data to i64**)
ret i64* %v
}
define i64 addrspace(2)* @load_non_integral_ptr_from_i8_data() {
; CHECK-LABEL: @load_non_integral_ptr_from_i8_data(
; CHECK-NEXT: [[V:%.*]] = load i64 addrspace(2)*, i64 addrspace(2)** bitcast ([16 x i8]* @g_i8_data to i64 addrspace(2)**), align 8
; CHECK-NEXT: ret i64 addrspace(2)* [[V]]
;
%v = load i64 addrspace(2)*, i64 addrspace(2)** bitcast ([16 x i8]* @g_i8_data to i64 addrspace(2)**)
ret i64 addrspace(2)* %v
}
@g_i1 = constant i1 true
define i8 @load_i8_from_i1() {
; CHECK-LABEL: @load_i8_from_i1(
; CHECK-NEXT: ret i8 -1
;
%v = load i8, i8* bitcast (i1* @g_i1 to i8*)
ret i8 %v
}