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
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, i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @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, i16* bitcast(i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*)
33 ; FIXME: Should be able to load through a constant addrspacecast.
34 define 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]]
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)*)
43 ; Load of second 16 bits of 32-bit value.
46 ; LE-NEXT: ret i16 -8531
49 ; BE-NEXT: ret i16 -16657
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)
55 ; Load of 8 bit field + tail padding.
58 ; LE-NEXT: ret i16 186
61 ; BE-NEXT: ret i16 -17920
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)
67 ; Load of double bits.
69 ; CHECK-LABEL: @test6(
70 ; CHECK-NEXT: ret i64 4607182418800017408
72 %r = load i64, i64* bitcast(double* @g2 to i64*)
76 ; Load of double bits.
82 ; BE-NEXT: ret i16 16368
84 %r = load i16, i16* bitcast(double* @g2 to i16*)
89 define double @test8() {
91 ; LE-NEXT: ret double 0xBADEADBEEF
94 ; BE-NEXT: ret double 0xDEADBEEFBA000000
96 %r = load double, double* bitcast({{i32,i8},i32}* @g1 to double*)
102 define i128 @test9() {
104 ; LE-NEXT: ret i128 2071796475790618158476296315
107 ; BE-NEXT: ret i128 2268949521066387161080
109 %r = load i128, i128* bitcast({i64, i64}* @g3 to i128*)
114 define <2 x i64> @test10() {
115 ; CHECK-LABEL: @test10(
116 ; CHECK-NEXT: ret <2 x i64> <i64 123, i64 112312312>
118 %r = load <2 x i64>, <2 x i64>* bitcast({i64, i64}* @g3 to <2 x i64>*)
125 @g4 = internal constant { i8, i8 } { i8 -95, i8 8 }
127 define i16 @test11() nounwind {
130 ; LE-NEXT: ret i16 2209
134 ; BE-NEXT: ret i16 -24312
137 %a = load i16, i16* bitcast ({ i8, i8 }* @g4 to i16*)
143 @test12g = private constant [6 x i8] c"a\00b\00\00\00"
145 define i16 @test12() {
147 ; LE-NEXT: ret i16 98
150 ; BE-NEXT: ret i16 25088
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)
159 define i1 @test13() {
160 ; CHECK-LABEL: @test13(
161 ; CHECK-NEXT: ret i1 false
163 %A = load i1, i1* bitcast (i8* @g5 to i1*)
167 @g6 = constant [2 x i8*] [i8* inttoptr (i64 1 to i8*), i8* inttoptr (i64 2 to i8*)]
168 define i64 @test14() nounwind {
169 ; CHECK-LABEL: @test14(
171 ; CHECK-NEXT: ret i64 1
174 %tmp = load i64, i64* bitcast ([2 x i8*]* @g6 to i64*)
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)*)]
180 define i16 @test14_as1() nounwind {
181 ; CHECK-LABEL: @test14_as1(
183 ; CHECK-NEXT: ret i16 1
186 %tmp = load i16, i16* bitcast ([2 x i8 addrspace(1)*]* @g6_as1 to i16*)
190 define i64 @test15() nounwind {
191 ; CHECK-LABEL: @test15(
193 ; CHECK-NEXT: ret i64 2
196 %tmp = load i64, i64* bitcast (i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @g6, i32 0, i64 1) to i64*)
200 @gv7 = constant [4 x i8*] [i8* null, i8* inttoptr (i64 -14 to i8*), i8* null, i8* null]
201 define i64 @test16.1() {
202 ; CHECK-LABEL: @test16.1(
203 ; CHECK-NEXT: ret i64 0
205 %v = load i64, i64* bitcast ([4 x i8*]* @gv7 to i64*), align 8
209 define i64 @test16.2() {
210 ; CHECK-LABEL: @test16.2(
211 ; CHECK-NEXT: ret i64 -14
213 %v = load i64, i64* bitcast (i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @gv7, i64 0, i64 1) to i64*), align 8
217 define i64 @test16.3() {
218 ; CHECK-LABEL: @test16.3(
219 ; CHECK-NEXT: ret i64 0
221 %v = load i64, i64* bitcast (i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @gv7, i64 0, i64 2) to i64*), align 8
225 @g7 = constant {[0 x i32], [0 x i8], {}*} { [0 x i32] undef, [0 x i8] undef, {}* null }
227 define i64* @test_leading_zero_size_elems() {
228 ; CHECK-LABEL: @test_leading_zero_size_elems(
229 ; CHECK-NEXT: ret i64* null
231 %v = load i64*, i64** bitcast ({[0 x i32], [0 x i8], {}*}* @g7 to i64**)
235 @g8 = constant {[4294967295 x [0 x i32]], i64} { [4294967295 x [0 x i32]] undef, i64 123 }
237 define i64 @test_leading_zero_size_elems_big() {
238 ; CHECK-LABEL: @test_leading_zero_size_elems_big(
239 ; CHECK-NEXT: ret i64 123
241 %v = load i64, i64* bitcast ({[4294967295 x [0 x i32]], i64}* @g8 to i64*)
245 @g9 = constant [4294967295 x [0 x i32]] zeroinitializer
247 define i64 @test_array_of_zero_size_array() {
248 ; CHECK-LABEL: @test_array_of_zero_size_array(
249 ; CHECK-NEXT: ret i64 0
251 %v = load i64, i64* bitcast ([4294967295 x [0 x i32]]* @g9 to i64*)
255 @g10 = constant {i128} {i128 undef}
257 define i32* @test_undef_aggregate() {
258 ; CHECK-LABEL: @test_undef_aggregate(
259 ; CHECK-NEXT: ret i32* undef
261 %v = load i32*, i32** bitcast ({i128}* @g10 to i32**)