blob: dbfd992179069ec3122669c96b64325d37b83324 [file] [log] [blame]
Matt Arsenault7a960a82013-08-20 21:20:04 +00001; 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
Chris Lattnered00b802009-10-23 06:23:49 +00003
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +00004; {{ 0xDEADBEEF, 0xBA }, 0xCAFEBABE}
Chris Lattner9e2d5b32009-10-24 05:22:15 +00005@g1 = constant {{i32,i8},i32} {{i32,i8} { i32 -559038737, i8 186 }, i32 -889275714 }
6@g2 = constant double 1.0
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +00007; { 0x7B, 0x06B1BFF8 }
Chris Lattner9e2d5b32009-10-24 05:22:15 +00008@g3 = constant {i64, i64} { i64 123, i64 112312312 }
Chris Lattnered00b802009-10-23 06:23:49 +00009
10; Simple load
11define i32 @test1() {
David Blaikiea79ac142015-02-27 21:17:42 +000012 %r = load i32, i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0)
Chris Lattnered00b802009-10-23 06:23:49 +000013 ret i32 %r
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000014
15; 0xDEADBEEF
Stephen Linc1c7a132013-07-14 01:42:54 +000016; LE-LABEL: @test1(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000017; LE: ret i32 -559038737
18
19; 0xDEADBEEF
Stephen Linc1c7a132013-07-14 01:42:54 +000020; BE-LABEL: @test1(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000021; BE: ret i32 -559038737
Chris Lattnered00b802009-10-23 06:23:49 +000022}
23
24; PR3152
25; Load of first 16 bits of 32-bit value.
26define i16 @test2() {
David Blaikiea79ac142015-02-27 21:17:42 +000027 %r = load i16, i16* bitcast(i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*)
Chris Lattnered00b802009-10-23 06:23:49 +000028 ret i16 %r
29
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000030; 0xBEEF
Stephen Linc1c7a132013-07-14 01:42:54 +000031; LE-LABEL: @test2(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000032; LE: ret i16 -16657
33
34; 0xDEAD
Stephen Linc1c7a132013-07-14 01:42:54 +000035; BE-LABEL: @test2(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000036; BE: ret i16 -8531
Chris Lattnered00b802009-10-23 06:23:49 +000037}
38
Matt Arsenaultcaa9c712014-07-14 22:39:26 +000039define i16 @test2_addrspacecast() {
David Blaikiea79ac142015-02-27 21:17:42 +000040 %r = load i16, i16 addrspace(1)* addrspacecast(i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16 addrspace(1)*)
Matt Arsenaultcaa9c712014-07-14 22:39:26 +000041 ret i16 %r
42
43; 0xBEEF
44; LE-LABEL: @test2_addrspacecast(
45; LE: ret i16 -16657
46
47; 0xDEAD
48; BE-LABEL: @test2_addrspacecast(
49; BE: ret i16 -8531
50}
51
Chris Lattnered00b802009-10-23 06:23:49 +000052; Load of second 16 bits of 32-bit value.
53define i16 @test3() {
David Blaikiea79ac142015-02-27 21:17:42 +000054 %r = load i16, i16* getelementptr(i16* bitcast(i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*), i32 1)
Chris Lattnered00b802009-10-23 06:23:49 +000055 ret i16 %r
56
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000057; 0xDEAD
Stephen Linc1c7a132013-07-14 01:42:54 +000058; LE-LABEL: @test3(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000059; LE: ret i16 -8531
60
61; 0xBEEF
Stephen Linc1c7a132013-07-14 01:42:54 +000062; BE-LABEL: @test3(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000063; BE: ret i16 -16657
Chris Lattnered00b802009-10-23 06:23:49 +000064}
65
66; Load of 8 bit field + tail padding.
67define i16 @test4() {
David Blaikiea79ac142015-02-27 21:17:42 +000068 %r = load i16, i16* getelementptr(i16* bitcast(i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*), i32 2)
Chris Lattnered00b802009-10-23 06:23:49 +000069 ret i16 %r
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000070
71; 0x00BA
Stephen Linc1c7a132013-07-14 01:42:54 +000072; LE-LABEL: @test4(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000073; LE: ret i16 186
74
75; 0xBA00
Stephen Linc1c7a132013-07-14 01:42:54 +000076; BE-LABEL: @test4(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000077; BE: ret i16 -17920
Chris Lattnered00b802009-10-23 06:23:49 +000078}
79
80; Load of double bits.
81define i64 @test6() {
David Blaikiea79ac142015-02-27 21:17:42 +000082 %r = load i64, i64* bitcast(double* @g2 to i64*)
Chris Lattnered00b802009-10-23 06:23:49 +000083 ret i64 %r
84
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000085; 0x3FF_0000000000000
Stephen Linc1c7a132013-07-14 01:42:54 +000086; LE-LABEL: @test6(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000087; LE: ret i64 4607182418800017408
88
89; 0x3FF_0000000000000
Stephen Linc1c7a132013-07-14 01:42:54 +000090; BE-LABEL: @test6(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000091; BE: ret i64 4607182418800017408
Chris Lattnered00b802009-10-23 06:23:49 +000092}
93
94; Load of double bits.
95define i16 @test7() {
David Blaikiea79ac142015-02-27 21:17:42 +000096 %r = load i16, i16* bitcast(double* @g2 to i16*)
Chris Lattnered00b802009-10-23 06:23:49 +000097 ret i16 %r
98
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000099; 0x0000
Stephen Linc1c7a132013-07-14 01:42:54 +0000100; LE-LABEL: @test7(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000101; LE: ret i16 0
102
103; 0x3FF0
Stephen Linc1c7a132013-07-14 01:42:54 +0000104; BE-LABEL: @test7(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000105; BE: ret i16 16368
Chris Lattnered00b802009-10-23 06:23:49 +0000106}
107
108; Double load.
109define double @test8() {
David Blaikiea79ac142015-02-27 21:17:42 +0000110 %r = load double, double* bitcast({{i32,i8},i32}* @g1 to double*)
Chris Lattnered00b802009-10-23 06:23:49 +0000111 ret double %r
112
Stephen Linc1c7a132013-07-14 01:42:54 +0000113; LE-LABEL: @test8(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000114; LE: ret double 0xBADEADBEEF
115
Stephen Linc1c7a132013-07-14 01:42:54 +0000116; BE-LABEL: @test8(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000117; BE: ret double 0xDEADBEEFBA000000
Chris Lattnered00b802009-10-23 06:23:49 +0000118}
Chris Lattner59f94c02009-10-23 06:50:36 +0000119
120
121; i128 load.
122define i128 @test9() {
David Blaikiea79ac142015-02-27 21:17:42 +0000123 %r = load i128, i128* bitcast({i64, i64}* @g3 to i128*)
Chris Lattner59f94c02009-10-23 06:50:36 +0000124 ret i128 %r
125
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000126; 0x00000000_06B1BFF8_00000000_0000007B
Stephen Linc1c7a132013-07-14 01:42:54 +0000127; LE-LABEL: @test9(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000128; LE: ret i128 2071796475790618158476296315
129
130; 0x00000000_0000007B_00000000_06B1BFF8
Stephen Linc1c7a132013-07-14 01:42:54 +0000131; BE-LABEL: @test9(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000132; BE: ret i128 2268949521066387161080
Chris Lattner59f94c02009-10-23 06:50:36 +0000133}
Chris Lattnerccf1e842009-10-23 06:57:37 +0000134
135; vector load.
136define <2 x i64> @test10() {
David Blaikiea79ac142015-02-27 21:17:42 +0000137 %r = load <2 x i64>, <2 x i64>* bitcast({i64, i64}* @g3 to <2 x i64>*)
Chris Lattnerccf1e842009-10-23 06:57:37 +0000138 ret <2 x i64> %r
139
Stephen Linc1c7a132013-07-14 01:42:54 +0000140; LE-LABEL: @test10(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000141; LE: ret <2 x i64> <i64 123, i64 112312312>
142
Stephen Linc1c7a132013-07-14 01:42:54 +0000143; BE-LABEL: @test10(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000144; BE: ret <2 x i64> <i64 123, i64 112312312>
Chris Lattnerccf1e842009-10-23 06:57:37 +0000145}
146
Chris Lattner9e2d5b32009-10-24 05:22:15 +0000147
148; PR5287
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000149; { 0xA1, 0x08 }
Chris Lattner9e2d5b32009-10-24 05:22:15 +0000150@g4 = internal constant { i8, i8 } { i8 -95, i8 8 }
151
152define i16 @test11() nounwind {
153entry:
David Blaikiea79ac142015-02-27 21:17:42 +0000154 %a = load i16, i16* bitcast ({ i8, i8 }* @g4 to i16*)
Chris Lattner9e2d5b32009-10-24 05:22:15 +0000155 ret i16 %a
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000156
157; 0x08A1
Stephen Linc1c7a132013-07-14 01:42:54 +0000158; LE-LABEL: @test11(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000159; LE: ret i16 2209
160
161; 0xA108
Stephen Linc1c7a132013-07-14 01:42:54 +0000162; BE-LABEL: @test11(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000163; BE: ret i16 -24312
Chris Lattner9e2d5b32009-10-24 05:22:15 +0000164}
165
166
Chris Lattner1ddfd9f2009-12-04 06:29:29 +0000167; PR5551
168@test12g = private constant [6 x i8] c"a\00b\00\00\00"
169
170define i16 @test12() {
David Blaikiea79ac142015-02-27 21:17:42 +0000171 %a = load i16, i16* getelementptr inbounds ([3 x i16]* bitcast ([6 x i8]* @test12g to [3 x i16]*), i32 0, i64 1)
Chris Lattner1ddfd9f2009-12-04 06:29:29 +0000172 ret i16 %a
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000173
174; 0x0062
Stephen Linc1c7a132013-07-14 01:42:54 +0000175; LE-LABEL: @test12(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000176; LE: ret i16 98
177
178; 0x6200
Stephen Linc1c7a132013-07-14 01:42:54 +0000179; BE-LABEL: @test12(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000180; BE: ret i16 25088
Chris Lattner1ddfd9f2009-12-04 06:29:29 +0000181}
Chris Lattnera69f89c2010-01-08 19:02:23 +0000182
183
184; PR5978
185@g5 = constant i8 4
186define i1 @test13() {
David Blaikiea79ac142015-02-27 21:17:42 +0000187 %A = load i1, i1* bitcast (i8* @g5 to i1*)
Chris Lattnera69f89c2010-01-08 19:02:23 +0000188 ret i1 %A
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000189
Stephen Linc1c7a132013-07-14 01:42:54 +0000190; LE-LABEL: @test13(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000191; LE: ret i1 false
192
Stephen Linc1c7a132013-07-14 01:42:54 +0000193; BE-LABEL: @test13(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000194; BE: ret i1 false
Chris Lattnera69f89c2010-01-08 19:02:23 +0000195}
Anders Carlssond21b06a2011-02-06 20:11:56 +0000196
197@g6 = constant [2 x i8*] [i8* inttoptr (i64 1 to i8*), i8* inttoptr (i64 2 to i8*)]
198define i64 @test14() nounwind {
199entry:
David Blaikiea79ac142015-02-27 21:17:42 +0000200 %tmp = load i64, i64* bitcast ([2 x i8*]* @g6 to i64*)
Anders Carlssond21b06a2011-02-06 20:11:56 +0000201 ret i64 %tmp
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000202
Stephen Linc1c7a132013-07-14 01:42:54 +0000203; LE-LABEL: @test14(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000204; LE: ret i64 1
205
Stephen Linc1c7a132013-07-14 01:42:54 +0000206; BE-LABEL: @test14(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000207; BE: ret i64 1
Anders Carlssond21b06a2011-02-06 20:11:56 +0000208}
209
Matt Arsenault7a960a82013-08-20 21:20:04 +0000210; Check with address space pointers
211@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)*)]
212define i16 @test14_as1() nounwind {
213entry:
David Blaikiea79ac142015-02-27 21:17:42 +0000214 %tmp = load i16, i16* bitcast ([2 x i8 addrspace(1)*]* @g6_as1 to i16*)
Matt Arsenault7a960a82013-08-20 21:20:04 +0000215 ret i16 %tmp
216
217; LE: @test14_as1
218; LE: ret i16 1
219
220; BE: @test14_as1
221; BE: ret i16 1
222}
223
Anders Carlssond21b06a2011-02-06 20:11:56 +0000224define i64 @test15() nounwind {
225entry:
David Blaikiea79ac142015-02-27 21:17:42 +0000226 %tmp = load i64, i64* bitcast (i8** getelementptr inbounds ([2 x i8*]* @g6, i32 0, i64 1) to i64*)
Anders Carlssond21b06a2011-02-06 20:11:56 +0000227 ret i64 %tmp
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000228
Stephen Linc1c7a132013-07-14 01:42:54 +0000229; LE-LABEL: @test15(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000230; LE: ret i64 2
231
Stephen Linc1c7a132013-07-14 01:42:54 +0000232; BE-LABEL: @test15(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000233; BE: ret i64 2
Anders Carlssond21b06a2011-02-06 20:11:56 +0000234}
Chandler Carrutha0e56952014-05-15 09:56:28 +0000235
236@gv7 = constant [4 x i8*] [i8* null, i8* inttoptr (i64 -14 to i8*), i8* null, i8* null]
237define i64 @test16.1() {
David Blaikiea79ac142015-02-27 21:17:42 +0000238 %v = load i64, i64* bitcast ([4 x i8*]* @gv7 to i64*), align 8
Chandler Carrutha0e56952014-05-15 09:56:28 +0000239 ret i64 %v
240
241; LE-LABEL: @test16.1(
242; LE: ret i64 0
243
244; BE-LABEL: @test16.1(
245; BE: ret i64 0
246}
247
248define i64 @test16.2() {
David Blaikiea79ac142015-02-27 21:17:42 +0000249 %v = load i64, i64* bitcast (i8** getelementptr inbounds ([4 x i8*]* @gv7, i64 0, i64 1) to i64*), align 8
Chandler Carrutha0e56952014-05-15 09:56:28 +0000250 ret i64 %v
251
252; LE-LABEL: @test16.2(
253; LE: ret i64 -14
254
255; BE-LABEL: @test16.2(
256; BE: ret i64 -14
257}
258
259define i64 @test16.3() {
David Blaikiea79ac142015-02-27 21:17:42 +0000260 %v = load i64, i64* bitcast (i8** getelementptr inbounds ([4 x i8*]* @gv7, i64 0, i64 2) to i64*), align 8
Chandler Carrutha0e56952014-05-15 09:56:28 +0000261 ret i64 %v
262
263; LE-LABEL: @test16.3(
264; LE: ret i64 0
265
266; BE-LABEL: @test16.3(
267; BE: ret i64 0
268}