1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; 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
3 ; 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
5 ; {{ 0xDEADBEEF, 0xBA }, 0xCAFEBABE}
6 @g1 = constant {{i32,i8},i32} {{i32,i8} { i32 -559038737, i8 186 }, i32 -889275714 }
7 @g2 = constant double 1.0
9 @g3 = constant {i64, i64} { i64 123, i64 112312312 }
13 ; CHECK-LABEL: @test1(
14 ; CHECK-NEXT: ret i32 -559038737
16 %r = load i32, ptr getelementptr ({{i32,i8},i32}, ptr @g1, i32 0, i32 0, i32 0)
21 ; Load of first 16 bits of 32-bit value.
24 ; LE-NEXT: ret i16 -16657
27 ; BE-NEXT: ret i16 -8531
29 %r = load i16, ptr getelementptr ({{i32,i8},i32}, ptr @g1, i32 0, i32 0, i32 0)
33 define i16 @test2_addrspacecast() {
34 ; LE-LABEL: @test2_addrspacecast(
35 ; LE-NEXT: ret i16 -16657
37 ; BE-LABEL: @test2_addrspacecast(
38 ; BE-NEXT: ret i16 -8531
40 %r = load i16, ptr addrspace(1) addrspacecast(ptr getelementptr ({{i32,i8},i32}, ptr @g1, i32 0, i32 0, i32 0) to ptr addrspace(1))
44 ; Load of second 16 bits of 32-bit value.
47 ; LE-NEXT: ret i16 -8531
50 ; BE-NEXT: ret i16 -16657
52 %r = load i16, ptr getelementptr(i16, ptr getelementptr ({{i32,i8},i32}, ptr @g1, i32 0, i32 0, i32 0), i32 1)
56 ; Load of 8 bit field + tail padding.
59 ; LE-NEXT: ret i16 186
62 ; BE-NEXT: ret i16 -17920
64 %r = load i16, ptr getelementptr(i16, ptr getelementptr ({{i32,i8},i32}, ptr @g1, i32 0, i32 0, i32 0), i32 2)
68 ; Load of double bits.
70 ; CHECK-LABEL: @test6(
71 ; CHECK-NEXT: ret i64 4607182418800017408
73 %r = load i64, ptr @g2
77 ; Load of double bits.
83 ; BE-NEXT: ret i16 16368
85 %r = load i16, ptr @g2
90 define double @test8() {
92 ; LE-NEXT: ret double 0xBADEADBEEF
95 ; BE-NEXT: ret double 0xDEADBEEFBA000000
97 %r = load double, ptr @g1
103 define i128 @test_i128() {
104 ; LE-LABEL: @test_i128(
105 ; LE-NEXT: ret i128 2071796475790618158476296315
107 ; BE-LABEL: @test_i128(
108 ; BE-NEXT: ret i128 2268949521066387161080
110 %r = load i128, ptr @g3
114 define fp128 @test_fp128() {
115 ; LE-LABEL: @test_fp128(
116 ; LE-NEXT: ret fp128 0xL000000000000007B0000000006B1BFF8
118 ; BE-LABEL: @test_fp128(
119 ; BE-NEXT: ret fp128 0xL0000000006B1BFF8000000000000007B
121 %r = load fp128, ptr @g3
125 define ppc_fp128 @test_ppc_fp128() {
126 ; LE-LABEL: @test_ppc_fp128(
127 ; LE-NEXT: ret ppc_fp128 bitcast (i128 2071796475790618158476296315 to ppc_fp128)
129 ; BE-LABEL: @test_ppc_fp128(
130 ; BE-NEXT: ret ppc_fp128 bitcast (i128 2268949521066387161080 to ppc_fp128)
132 %r = load ppc_fp128, ptr @g3
136 define x86_fp80 @test_x86_fp80() {
137 ; LE-LABEL: @test_x86_fp80(
138 ; LE-NEXT: ret x86_fp80 0xKFFFF000000000000007B
140 ; BE-LABEL: @test_x86_fp80(
141 ; BE-NEXT: ret x86_fp80 0xK000000000000007B0000
143 %r = load x86_fp80, ptr @g3
147 define bfloat @test_bfloat() {
148 ; LE-LABEL: @test_bfloat(
149 ; LE-NEXT: ret bfloat 0xR007B
151 ; BE-LABEL: @test_bfloat(
152 ; BE-NEXT: ret bfloat 0xR0000
154 %r = load bfloat, ptr @g3
159 define <2 x i64> @test10() {
160 ; CHECK-LABEL: @test10(
161 ; CHECK-NEXT: ret <2 x i64> <i64 123, i64 112312312>
163 %r = load <2 x i64>, ptr @g3
170 @g4 = internal constant { i8, i8 } { i8 -95, i8 8 }
172 define i16 @test11() nounwind {
175 ; LE-NEXT: ret i16 2209
179 ; BE-NEXT: ret i16 -24312
182 %a = load i16, ptr @g4
188 @test12g = private constant [6 x i8] c"a\00b\00\00\00"
190 define i16 @test12() {
192 ; LE-NEXT: ret i16 98
195 ; BE-NEXT: ret i16 25088
197 %a = load i16, ptr getelementptr inbounds ([3 x i16], ptr @test12g, i32 0, i64 1)
204 define i1 @test13() {
205 ; CHECK-LABEL: @test13(
206 ; CHECK-NEXT: ret i1 false
208 %A = load i1, ptr @g5
212 @g6 = constant [2 x ptr] [ptr inttoptr (i64 1 to ptr), ptr inttoptr (i64 2 to ptr)]
213 define i64 @test14() nounwind {
214 ; CHECK-LABEL: @test14(
216 ; CHECK-NEXT: ret i64 1
219 %tmp = load i64, ptr @g6
223 ; Check with address space pointers
224 @g6_as1 = constant [2 x ptr addrspace(1)] [ptr addrspace(1) inttoptr (i16 1 to ptr addrspace(1)), ptr addrspace(1) inttoptr (i16 2 to ptr addrspace(1))]
225 define i16 @test14_as1() nounwind {
226 ; CHECK-LABEL: @test14_as1(
228 ; CHECK-NEXT: ret i16 1
231 %tmp = load i16, ptr @g6_as1
235 define i64 @test15() nounwind {
236 ; CHECK-LABEL: @test15(
238 ; CHECK-NEXT: ret i64 2
241 %tmp = load i64, ptr getelementptr inbounds ([2 x ptr], ptr @g6, i32 0, i64 1)
245 @gv7 = constant [4 x ptr] [ptr null, ptr inttoptr (i64 -14 to ptr), ptr null, ptr null]
246 define i64 @test16.1() {
247 ; CHECK-LABEL: @test16.1(
248 ; CHECK-NEXT: ret i64 0
250 %v = load i64, ptr @gv7, align 8
254 define i64 @test16.2() {
255 ; CHECK-LABEL: @test16.2(
256 ; CHECK-NEXT: ret i64 -14
258 %v = load i64, ptr getelementptr inbounds ([4 x ptr], ptr @gv7, i64 0, i64 1), align 8
262 define i64 @test16.3() {
263 ; CHECK-LABEL: @test16.3(
264 ; CHECK-NEXT: ret i64 0
266 %v = load i64, ptr getelementptr inbounds ([4 x ptr], ptr @gv7, i64 0, i64 2), align 8
270 @g7 = constant {[0 x i32], [0 x i8], ptr} { [0 x i32] poison, [0 x i8] poison, ptr null }
272 define ptr @test_leading_zero_size_elems() {
273 ; CHECK-LABEL: @test_leading_zero_size_elems(
274 ; CHECK-NEXT: ret ptr null
276 %v = load ptr, ptr @g7
280 @g8 = constant {[4294967295 x [0 x i32]], i64} { [4294967295 x [0 x i32]] poison, i64 123 }
282 define i64 @test_leading_zero_size_elems_big() {
283 ; CHECK-LABEL: @test_leading_zero_size_elems_big(
284 ; CHECK-NEXT: ret i64 123
286 %v = load i64, ptr @g8
290 @g9 = constant [4294967295 x [0 x i32]] zeroinitializer
292 define i64 @test_array_of_zero_size_array() {
293 ; CHECK-LABEL: @test_array_of_zero_size_array(
294 ; CHECK-NEXT: ret i64 poison
296 %v = load i64, ptr @g9
300 @g_undef = constant { i128 } undef
302 define ptr @test_undef_aggregate() {
303 ; CHECK-LABEL: @test_undef_aggregate(
304 ; CHECK-NEXT: ret ptr undef
306 %v = load ptr, ptr @g_undef
310 @g_poison = constant { i128 } poison
312 define ptr @test_poison_aggregate() {
313 ; CHECK-LABEL: @test_poison_aggregate(
314 ; CHECK-NEXT: ret ptr poison
316 %v = load ptr, ptr @g_poison
320 @g11 = constant <{ [8 x i8], [8 x i8] }> <{ [8 x i8] poison, [8 x i8] zeroinitializer }>, align 4
322 define ptr @test_trailing_zero_gep_index() {
323 ; CHECK-LABEL: @test_trailing_zero_gep_index(
324 ; CHECK-NEXT: ret ptr null
326 %v = load ptr, ptr getelementptr inbounds (<{ [8 x i8], [8 x i8] }>, ptr @g11, i32 0, i32 1, i32 0), align 4
330 define { i64, i64 } @test_load_struct() {
331 ; CHECK-LABEL: @test_load_struct(
332 ; CHECK-NEXT: ret { i64, i64 } { i64 123, i64 112312312 }
334 %v = load { i64, i64 }, ptr @g3
338 @g_offset = external global i64
340 @g_neg_one_vec = constant <4 x i8> <i8 -1, i8 -1, i8 -1, i8 -1>
342 define i8 @load_neg_one_at_unknown_offset() {
343 ; CHECK-LABEL: @load_neg_one_at_unknown_offset(
344 ; CHECK-NEXT: ret i8 -1
346 %v = load i8, ptr getelementptr (<4 x i8>, ptr @g_neg_one_vec, i64 0, i64 ptrtoint (ptr @g_offset to i64))
350 @g_with_padding = constant { i32, [4 x i8] } { i32 0, [4 x i8] poison }
352 define i32 @load_padding() {
353 ; CHECK-LABEL: @load_padding(
354 ; CHECK-NEXT: ret i32 poison
356 %v = load i32, ptr getelementptr (i32, ptr @g_with_padding, i64 1)
360 @g_all_poison = constant { i32, [4 x i8] } poison
362 ; Same as the previous case, but with an all-poison initializer.
363 define i32 @load_all_poison() {
364 ; CHECK-LABEL: @load_all_poison(
365 ; CHECK-NEXT: ret i32 poison
367 %v = load i32, ptr getelementptr (i32, ptr @g_all_poison, i64 1)
371 @g_i8_data = constant [16 x i8] c"\01\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
373 define ptr @load_ptr_from_i8_data() {
374 ; LE-LABEL: @load_ptr_from_i8_data(
375 ; LE-NEXT: ret ptr inttoptr (i64 1 to ptr)
377 ; BE-LABEL: @load_ptr_from_i8_data(
378 ; BE-NEXT: ret ptr inttoptr (i64 72057594037927936 to ptr)
380 %v = load ptr, ptr @g_i8_data
384 define ptr addrspace(2) @load_non_integral_ptr_from_i8_data() {
385 ; CHECK-LABEL: @load_non_integral_ptr_from_i8_data(
386 ; CHECK-NEXT: [[V:%.*]] = load ptr addrspace(2), ptr @g_i8_data, align 8
387 ; CHECK-NEXT: ret ptr addrspace(2) [[V]]
389 %v = load ptr addrspace(2), ptr @g_i8_data
390 ret ptr addrspace(2) %v
393 @g_i1 = constant i1 true
395 define i8 @load_i8_from_i1() {
396 ; CHECK-LABEL: @load_i8_from_i1(
397 ; CHECK-NEXT: [[V:%.*]] = load i8, ptr @g_i1, align 1
398 ; CHECK-NEXT: ret i8 [[V]]
400 %v = load i8, ptr @g_i1
404 @global9 = internal constant i9 -1
406 ; Reproducer for https://github.com/llvm/llvm-project/issues/81793
407 define i8 @load_i8_from_i9() {
408 ; CHECK-LABEL: @load_i8_from_i9(
409 ; CHECK-NEXT: [[V:%.*]] = load i8, ptr @global9, align 1
410 ; CHECK-NEXT: ret i8 [[V]]
412 %v = load i8, ptr @global9
416 define i9 @load_i9_from_i9() {
417 ; CHECK-LABEL: @load_i9_from_i9(
418 ; CHECK-NEXT: ret i9 -1
420 %v = load i9, ptr @global9
424 ; Reproducer for https://github.com/llvm/llvm-project/issues/81793
425 define i16 @load_i16_from_i17_store(ptr %p) {
426 ; CHECK-LABEL: @load_i16_from_i17_store(
427 ; CHECK-NEXT: store i17 -1, ptr [[P:%.*]], align 4
428 ; CHECK-NEXT: [[V:%.*]] = load i16, ptr @global9, align 2
429 ; CHECK-NEXT: ret i16 [[V]]
432 %v = load i16, ptr @global9
436 @global128 = internal constant i128 1125899906842625
437 define i128 @load-128bit(){
438 ; CHECK-LABEL: @load-128bit(
439 ; CHECK-NEXT: ret i128 1125899906842625
441 %1 = load i128, ptr @global128, align 4