blob: d05db47dcaaa87044f0024858b6c96a18a9ea7b3 [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() {
Chris Lattner9e2d5b32009-10-24 05:22:15 +000012 %r = load 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() {
Chris Lattner9e2d5b32009-10-24 05:22:15 +000027 %r = load 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
39; Load of second 16 bits of 32-bit value.
40define i16 @test3() {
Chris Lattner9e2d5b32009-10-24 05:22:15 +000041 %r = load 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 +000042 ret i16 %r
43
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000044; 0xDEAD
Stephen Linc1c7a132013-07-14 01:42:54 +000045; LE-LABEL: @test3(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000046; LE: ret i16 -8531
47
48; 0xBEEF
Stephen Linc1c7a132013-07-14 01:42:54 +000049; BE-LABEL: @test3(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000050; BE: ret i16 -16657
Chris Lattnered00b802009-10-23 06:23:49 +000051}
52
53; Load of 8 bit field + tail padding.
54define i16 @test4() {
Chris Lattner9e2d5b32009-10-24 05:22:15 +000055 %r = load 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 +000056 ret i16 %r
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000057
58; 0x00BA
Stephen Linc1c7a132013-07-14 01:42:54 +000059; LE-LABEL: @test4(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000060; LE: ret i16 186
61
62; 0xBA00
Stephen Linc1c7a132013-07-14 01:42:54 +000063; BE-LABEL: @test4(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000064; BE: ret i16 -17920
Chris Lattnered00b802009-10-23 06:23:49 +000065}
66
67; Load of double bits.
68define i64 @test6() {
Chris Lattner9e2d5b32009-10-24 05:22:15 +000069 %r = load i64* bitcast(double* @g2 to i64*)
Chris Lattnered00b802009-10-23 06:23:49 +000070 ret i64 %r
71
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000072; 0x3FF_0000000000000
Stephen Linc1c7a132013-07-14 01:42:54 +000073; LE-LABEL: @test6(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000074; LE: ret i64 4607182418800017408
75
76; 0x3FF_0000000000000
Stephen Linc1c7a132013-07-14 01:42:54 +000077; BE-LABEL: @test6(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000078; BE: ret i64 4607182418800017408
Chris Lattnered00b802009-10-23 06:23:49 +000079}
80
81; Load of double bits.
82define i16 @test7() {
Chris Lattner9e2d5b32009-10-24 05:22:15 +000083 %r = load i16* bitcast(double* @g2 to i16*)
Chris Lattnered00b802009-10-23 06:23:49 +000084 ret i16 %r
85
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000086; 0x0000
Stephen Linc1c7a132013-07-14 01:42:54 +000087; LE-LABEL: @test7(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000088; LE: ret i16 0
89
90; 0x3FF0
Stephen Linc1c7a132013-07-14 01:42:54 +000091; BE-LABEL: @test7(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +000092; BE: ret i16 16368
Chris Lattnered00b802009-10-23 06:23:49 +000093}
94
95; Double load.
96define double @test8() {
Chris Lattner9e2d5b32009-10-24 05:22:15 +000097 %r = load double* bitcast({{i32,i8},i32}* @g1 to double*)
Chris Lattnered00b802009-10-23 06:23:49 +000098 ret double %r
99
Stephen Linc1c7a132013-07-14 01:42:54 +0000100; LE-LABEL: @test8(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000101; LE: ret double 0xBADEADBEEF
102
Stephen Linc1c7a132013-07-14 01:42:54 +0000103; BE-LABEL: @test8(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000104; BE: ret double 0xDEADBEEFBA000000
Chris Lattnered00b802009-10-23 06:23:49 +0000105}
Chris Lattner59f94c02009-10-23 06:50:36 +0000106
107
108; i128 load.
109define i128 @test9() {
Chris Lattner9e2d5b32009-10-24 05:22:15 +0000110 %r = load i128* bitcast({i64, i64}* @g3 to i128*)
Chris Lattner59f94c02009-10-23 06:50:36 +0000111 ret i128 %r
112
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000113; 0x00000000_06B1BFF8_00000000_0000007B
Stephen Linc1c7a132013-07-14 01:42:54 +0000114; LE-LABEL: @test9(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000115; LE: ret i128 2071796475790618158476296315
116
117; 0x00000000_0000007B_00000000_06B1BFF8
Stephen Linc1c7a132013-07-14 01:42:54 +0000118; BE-LABEL: @test9(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000119; BE: ret i128 2268949521066387161080
Chris Lattner59f94c02009-10-23 06:50:36 +0000120}
Chris Lattnerccf1e842009-10-23 06:57:37 +0000121
122; vector load.
123define <2 x i64> @test10() {
Chris Lattner9e2d5b32009-10-24 05:22:15 +0000124 %r = load <2 x i64>* bitcast({i64, i64}* @g3 to <2 x i64>*)
Chris Lattnerccf1e842009-10-23 06:57:37 +0000125 ret <2 x i64> %r
126
Stephen Linc1c7a132013-07-14 01:42:54 +0000127; LE-LABEL: @test10(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000128; LE: ret <2 x i64> <i64 123, i64 112312312>
129
Stephen Linc1c7a132013-07-14 01:42:54 +0000130; BE-LABEL: @test10(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000131; BE: ret <2 x i64> <i64 123, i64 112312312>
Chris Lattnerccf1e842009-10-23 06:57:37 +0000132}
133
Chris Lattner9e2d5b32009-10-24 05:22:15 +0000134
135; PR5287
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000136; { 0xA1, 0x08 }
Chris Lattner9e2d5b32009-10-24 05:22:15 +0000137@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
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000143
144; 0x08A1
Stephen Linc1c7a132013-07-14 01:42:54 +0000145; LE-LABEL: @test11(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000146; LE: ret i16 2209
147
148; 0xA108
Stephen Linc1c7a132013-07-14 01:42:54 +0000149; BE-LABEL: @test11(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000150; BE: ret i16 -24312
Chris Lattner9e2d5b32009-10-24 05:22:15 +0000151}
152
153
Chris Lattner1ddfd9f2009-12-04 06:29:29 +0000154; PR5551
155@test12g = private constant [6 x i8] c"a\00b\00\00\00"
156
157define i16 @test12() {
Matt Arsenault7a960a82013-08-20 21:20:04 +0000158 %a = load 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 +0000159 ret i16 %a
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000160
161; 0x0062
Stephen Linc1c7a132013-07-14 01:42:54 +0000162; LE-LABEL: @test12(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000163; LE: ret i16 98
164
165; 0x6200
Stephen Linc1c7a132013-07-14 01:42:54 +0000166; BE-LABEL: @test12(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000167; BE: ret i16 25088
Chris Lattner1ddfd9f2009-12-04 06:29:29 +0000168}
Chris Lattnera69f89c2010-01-08 19:02:23 +0000169
170
171; PR5978
172@g5 = constant i8 4
173define i1 @test13() {
174 %A = load i1* bitcast (i8* @g5 to i1*)
175 ret i1 %A
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000176
Stephen Linc1c7a132013-07-14 01:42:54 +0000177; LE-LABEL: @test13(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000178; LE: ret i1 false
179
Stephen Linc1c7a132013-07-14 01:42:54 +0000180; BE-LABEL: @test13(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000181; BE: ret i1 false
Chris Lattnera69f89c2010-01-08 19:02:23 +0000182}
Anders Carlssond21b06a2011-02-06 20:11:56 +0000183
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
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000189
Stephen Linc1c7a132013-07-14 01:42:54 +0000190; LE-LABEL: @test14(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000191; LE: ret i64 1
192
Stephen Linc1c7a132013-07-14 01:42:54 +0000193; BE-LABEL: @test14(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000194; BE: ret i64 1
Anders Carlssond21b06a2011-02-06 20:11:56 +0000195}
196
Matt Arsenault7a960a82013-08-20 21:20:04 +0000197; 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
Anders Carlssond21b06a2011-02-06 20:11:56 +0000211define 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
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000215
Stephen Linc1c7a132013-07-14 01:42:54 +0000216; LE-LABEL: @test15(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000217; LE: ret i64 2
218
Stephen Linc1c7a132013-07-14 01:42:54 +0000219; BE-LABEL: @test15(
NAKAMURA Takumi43ab4ef2012-11-08 20:34:25 +0000220; BE: ret i64 2
Anders Carlssond21b06a2011-02-06 20:11:56 +0000221}