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-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" -instcombine -S | FileCheck %s --check-prefixes=CHECK,LE
3; RUN: opt < %s -data-layout="E-p:64:64:64-p1:16:16:16-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" -instcombine -S | FileCheck %s --check-prefixes=CHECK,BE
4
5; {{ 0xDEADBEEF, 0xBA }, 0xCAFEBABE}
6@g1 = constant {{i32,i8},i32} {{i32,i8} { i32 -559038737, i8 186 }, i32 -889275714 }
7@g2 = constant double 1.0
8; { 0x7B, 0x06B1BFF8 }
9@g3 = constant {i64, i64} { i64 123, i64 112312312 }
10
11; Simple load
12define i32 @test1() {
13; CHECK-LABEL: @test1(
14; CHECK-NEXT:    ret i32 -559038737
15;
16  %r = load i32, i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0)
17  ret i32 %r
18}
19
20; PR3152
21; Load of first 16 bits of 32-bit value.
22define i16 @test2() {
23; LE-LABEL: @test2(
24; LE-NEXT:    ret i16 -16657
25;
26; BE-LABEL: @test2(
27; BE-NEXT:    ret i16 -8531
28;
29  %r = load i16, i16* bitcast(i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*)
30  ret i16 %r
31}
32
33; FIXME: Should be able to load through a constant addrspacecast.
34define i16 @test2_addrspacecast() {
35; CHECK-LABEL: @test2_addrspacecast(
36; CHECK-NEXT:    [[R:%.*]] = load i16, i16 addrspace(1)* addrspacecast (i16* bitcast ({ { i32, i8 }, i32 }* @g1 to i16*) to i16 addrspace(1)*), align 8
37; CHECK-NEXT:    ret i16 [[R]]
38;
39  %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)*)
40  ret i16 %r
41}
42
43; Load of second 16 bits of 32-bit value.
44define i16 @test3() {
45; LE-LABEL: @test3(
46; LE-NEXT:    ret i16 -8531
47;
48; BE-LABEL: @test3(
49; BE-NEXT:    ret i16 -16657
50;
51  %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)
52  ret i16 %r
53}
54
55; Load of 8 bit field + tail padding.
56define i16 @test4() {
57; LE-LABEL: @test4(
58; LE-NEXT:    ret i16 186
59;
60; BE-LABEL: @test4(
61; BE-NEXT:    ret i16 -17920
62;
63  %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)
64  ret i16 %r
65}
66
67; Load of double bits.
68define i64 @test6() {
69; CHECK-LABEL: @test6(
70; CHECK-NEXT:    ret i64 4607182418800017408
71;
72  %r = load i64, i64* bitcast(double* @g2 to i64*)
73  ret i64 %r
74}
75
76; Load of double bits.
77define i16 @test7() {
78; LE-LABEL: @test7(
79; LE-NEXT:    ret i16 0
80;
81; BE-LABEL: @test7(
82; BE-NEXT:    ret i16 16368
83;
84  %r = load i16, i16* bitcast(double* @g2 to i16*)
85  ret i16 %r
86}
87
88; Double load.
89define double @test8() {
90; LE-LABEL: @test8(
91; LE-NEXT:    ret double 0xBADEADBEEF
92;
93; BE-LABEL: @test8(
94; BE-NEXT:    ret double 0xDEADBEEFBA000000
95;
96  %r = load double, double* bitcast({{i32,i8},i32}* @g1 to double*)
97  ret double %r
98}
99
100
101; i128 load.
102define i128 @test9() {
103; LE-LABEL: @test9(
104; LE-NEXT:    ret i128 2071796475790618158476296315
105;
106; BE-LABEL: @test9(
107; BE-NEXT:    ret i128 2268949521066387161080
108;
109  %r = load i128, i128* bitcast({i64, i64}* @g3 to i128*)
110  ret i128 %r
111}
112
113; vector load.
114define <2 x i64> @test10() {
115; CHECK-LABEL: @test10(
116; CHECK-NEXT:    ret <2 x i64> <i64 123, i64 112312312>
117;
118  %r = load <2 x i64>, <2 x i64>* bitcast({i64, i64}* @g3 to <2 x i64>*)
119  ret <2 x i64> %r
120}
121
122
123; PR5287
124; { 0xA1, 0x08 }
125@g4 = internal constant { i8, i8 } { i8 -95, i8 8 }
126
127define i16 @test11() nounwind {
128; LE-LABEL: @test11(
129; LE-NEXT:  entry:
130; LE-NEXT:    ret i16 2209
131;
132; BE-LABEL: @test11(
133; BE-NEXT:  entry:
134; BE-NEXT:    ret i16 -24312
135;
136entry:
137  %a = load i16, i16* bitcast ({ i8, i8 }* @g4 to i16*)
138  ret i16 %a
139}
140
141
142; PR5551
143@test12g = private constant [6 x i8] c"a\00b\00\00\00"
144
145define i16 @test12() {
146; LE-LABEL: @test12(
147; LE-NEXT:    ret i16 98
148;
149; BE-LABEL: @test12(
150; BE-NEXT:    ret i16 25088
151;
152  %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)
153  ret i16 %a
154}
155
156
157; PR5978
158@g5 = constant i8 4
159define i1 @test13() {
160; CHECK-LABEL: @test13(
161; CHECK-NEXT:    ret i1 false
162;
163  %A = load i1, i1* bitcast (i8* @g5 to i1*)
164  ret i1 %A
165}
166
167@g6 = constant [2 x i8*] [i8* inttoptr (i64 1 to i8*), i8* inttoptr (i64 2 to i8*)]
168define i64 @test14() nounwind {
169; CHECK-LABEL: @test14(
170; CHECK-NEXT:  entry:
171; CHECK-NEXT:    ret i64 1
172;
173entry:
174  %tmp = load i64, i64* bitcast ([2 x i8*]* @g6 to i64*)
175  ret i64 %tmp
176}
177
178; Check with address space pointers
179@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)*)]
180define i16 @test14_as1() nounwind {
181; CHECK-LABEL: @test14_as1(
182; CHECK-NEXT:  entry:
183; CHECK-NEXT:    ret i16 1
184;
185entry:
186  %tmp = load i16, i16* bitcast ([2 x i8 addrspace(1)*]* @g6_as1 to i16*)
187  ret i16 %tmp
188}
189
190define i64 @test15() nounwind {
191; CHECK-LABEL: @test15(
192; CHECK-NEXT:  entry:
193; CHECK-NEXT:    ret i64 2
194;
195entry:
196  %tmp = load i64, i64* bitcast (i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @g6, i32 0, i64 1) to i64*)
197  ret i64 %tmp
198}
199
200@gv7 = constant [4 x i8*] [i8* null, i8* inttoptr (i64 -14 to i8*), i8* null, i8* null]
201define i64 @test16.1() {
202; CHECK-LABEL: @test16.1(
203; CHECK-NEXT:    ret i64 0
204;
205  %v = load i64, i64* bitcast ([4 x i8*]* @gv7 to i64*), align 8
206  ret i64 %v
207}
208
209define i64 @test16.2() {
210; CHECK-LABEL: @test16.2(
211; CHECK-NEXT:    ret i64 -14
212;
213  %v = load i64, i64* bitcast (i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @gv7, i64 0, i64 1) to i64*), align 8
214  ret i64 %v
215}
216
217define i64 @test16.3() {
218; CHECK-LABEL: @test16.3(
219; CHECK-NEXT:    ret i64 0
220;
221  %v = load i64, i64* bitcast (i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @gv7, i64 0, i64 2) to i64*), align 8
222  ret i64 %v
223}
224
225@g7 = constant {[0 x i32], [0 x i8], {}*} { [0 x i32] undef, [0 x i8] undef, {}* null }
226
227define i64* @test_leading_zero_size_elems() {
228; CHECK-LABEL: @test_leading_zero_size_elems(
229; CHECK-NEXT:    ret i64* null
230;
231  %v = load i64*, i64** bitcast ({[0 x i32], [0 x i8], {}*}* @g7 to i64**)
232  ret i64* %v
233}
234
235@g8 = constant {[4294967295 x [0 x i32]], i64} { [4294967295 x [0 x i32]] undef, i64 123 }
236
237define i64 @test_leading_zero_size_elems_big() {
238; CHECK-LABEL: @test_leading_zero_size_elems_big(
239; CHECK-NEXT:    ret i64 123
240;
241  %v = load i64, i64* bitcast ({[4294967295 x [0 x i32]], i64}* @g8 to i64*)
242  ret i64 %v
243}
244
245@g9 = constant [4294967295 x [0 x i32]] zeroinitializer
246
247define i64 @test_array_of_zero_size_array() {
248; CHECK-LABEL: @test_array_of_zero_size_array(
249; CHECK-NEXT:    ret i64 0
250;
251  %v = load i64, i64* bitcast ([4294967295 x [0 x i32]]* @g9 to i64*)
252  ret i64 %v
253}
254
255@g10 = constant {i128} {i128 undef}
256
257define i32* @test_undef_aggregate() {
258; CHECK-LABEL: @test_undef_aggregate(
259; CHECK-NEXT:    ret i32* undef
260;
261  %v = load i32*, i32** bitcast ({i128}* @g10 to i32**)
262  ret i32* %v
263}
264