1 ; 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-prefix=LE
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-prefix=BE
4 ; {{ 0xDEADBEEF, 0xBA }, 0xCAFEBABE}
5 @g1 = constant {{i32,i8},i32} {{i32,i8} { i32 -559038737, i8 186 }, i32 -889275714 }
6 @g2 = constant double 1.0
8 @g3 = constant {i64, i64} { i64 123, i64 112312312 }
12 %r = load i32, i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0)
17 ; LE: ret i32 -559038737
21 ; BE: ret i32 -559038737
25 ; Load of first 16 bits of 32-bit value.
27 %r = load i16, i16* bitcast(i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*)
39 define i16 @test2_addrspacecast() {
40 %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)*)
43 ; FIXME: Should be able to load through a constant addrspacecast.
45 ; LE-LABEL: @test2_addrspacecast(
47 ; LE: load i16, i16 addrspace(1)* addrspacecast
50 ; BE-LABEL: @test2_addrspacecast(
52 ; BE: load i16, i16 addrspace(1)* addrspacecast
55 ; Load of second 16 bits of 32-bit value.
57 %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)
69 ; Load of 8 bit field + tail padding.
71 %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)
83 ; Load of double bits.
85 %r = load i64, i64* bitcast(double* @g2 to i64*)
90 ; LE: ret i64 4607182418800017408
94 ; BE: ret i64 4607182418800017408
97 ; Load of double bits.
99 %r = load i16, i16* bitcast(double* @g2 to i16*)
112 define double @test8() {
113 %r = load double, double* bitcast({{i32,i8},i32}* @g1 to double*)
117 ; LE: ret double 0xBADEADBEEF
120 ; BE: ret double 0xDEADBEEFBA000000
125 define i128 @test9() {
126 %r = load i128, i128* bitcast({i64, i64}* @g3 to i128*)
129 ; 0x00000000_06B1BFF8_00000000_0000007B
131 ; LE: ret i128 2071796475790618158476296315
133 ; 0x00000000_0000007B_00000000_06B1BFF8
135 ; BE: ret i128 2268949521066387161080
139 define <2 x i64> @test10() {
140 %r = load <2 x i64>, <2 x i64>* bitcast({i64, i64}* @g3 to <2 x i64>*)
144 ; LE: ret <2 x i64> <i64 123, i64 112312312>
147 ; BE: ret <2 x i64> <i64 123, i64 112312312>
153 @g4 = internal constant { i8, i8 } { i8 -95, i8 8 }
155 define i16 @test11() nounwind {
157 %a = load i16, i16* bitcast ({ i8, i8 }* @g4 to i16*)
171 @test12g = private constant [6 x i8] c"a\00b\00\00\00"
173 define i16 @test12() {
174 %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)
189 define i1 @test13() {
190 %A = load i1, i1* bitcast (i8* @g5 to i1*)
200 @g6 = constant [2 x i8*] [i8* inttoptr (i64 1 to i8*), i8* inttoptr (i64 2 to i8*)]
201 define i64 @test14() nounwind {
203 %tmp = load i64, i64* bitcast ([2 x i8*]* @g6 to i64*)
213 ; Check with address space pointers
214 @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)*)]
215 define i16 @test14_as1() nounwind {
217 %tmp = load i16, i16* bitcast ([2 x i8 addrspace(1)*]* @g6_as1 to i16*)
227 define i64 @test15() nounwind {
229 %tmp = load i64, i64* bitcast (i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @g6, i32 0, i64 1) to i64*)
239 @gv7 = constant [4 x i8*] [i8* null, i8* inttoptr (i64 -14 to i8*), i8* null, i8* null]
240 define i64 @test16.1() {
241 %v = load i64, i64* bitcast ([4 x i8*]* @gv7 to i64*), align 8
244 ; LE-LABEL: @test16.1(
247 ; BE-LABEL: @test16.1(
251 define i64 @test16.2() {
252 %v = load i64, i64* bitcast (i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @gv7, i64 0, i64 1) to i64*), align 8
255 ; LE-LABEL: @test16.2(
258 ; BE-LABEL: @test16.2(
262 define i64 @test16.3() {
263 %v = load i64, i64* bitcast (i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @gv7, i64 0, i64 2) to i64*), align 8
266 ; LE-LABEL: @test16.3(
269 ; BE-LABEL: @test16.3(
273 @g7 = constant {[0 x i32], [0 x i8], {}*} { [0 x i32] undef, [0 x i8] undef, {}* null }
275 define i64* @test_leading_zero_size_elems() {
276 %v = load i64*, i64** bitcast ({[0 x i32], [0 x i8], {}*}* @g7 to i64**)
279 ; LE-LABEL: @test_leading_zero_size_elems(
282 ; BE-LABEL: @test_leading_zero_size_elems(
286 @g8 = constant {[4294967295 x [0 x i32]], i64} { [4294967295 x [0 x i32]] undef, i64 123 }
288 define i64 @test_leading_zero_size_elems_big() {
289 %v = load i64, i64* bitcast ({[4294967295 x [0 x i32]], i64}* @g8 to i64*)
292 ; LE-LABEL: @test_leading_zero_size_elems_big(
295 ; BE-LABEL: @test_leading_zero_size_elems_big(
299 @g9 = constant [4294967295 x [0 x i32]] zeroinitializer
301 define i64 @test_array_of_zero_size_array() {
302 %v = load i64, i64* bitcast ([4294967295 x [0 x i32]]* @g9 to i64*)
305 ; LE-LABEL: @test_array_of_zero_size_array(
308 ; BE-LABEL: @test_array_of_zero_size_array(