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