xref: /llvm-project/llvm/test/Transforms/InstSimplify/bitcast-vector-fold.ll (revision 3654f1baa66f524c89e40ab24e18e594e56363e9)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
3; RUN: opt < %s -passes=instsimplify -use-constant-fp-for-fixed-length-splat -use-constant-int-for-fixed-length-splat -S | FileCheck %s
4target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-f64:32:64-v64:64:64-v128:128:128"
5
6define <2 x i64> @test1() {
7; CHECK-LABEL: @test1(
8; CHECK-NEXT:    ret <2 x i64> <i64 4294967296, i64 12884901890>
9;
10  %tmp3 = bitcast <4 x i32> < i32 0, i32 1, i32 2, i32 3 > to <2 x i64>
11  ret <2 x i64> %tmp3
12}
13
14define <4 x i32> @test2() {
15; CHECK-LABEL: @test2(
16; CHECK-NEXT:    ret <4 x i32> <i32 0, i32 0, i32 1, i32 0>
17;
18  %tmp3 = bitcast <2 x i64> < i64 0, i64 1 > to <4 x i32>
19  ret <4 x i32> %tmp3
20}
21
22define <2 x double> @test3() {
23; CHECK-LABEL: @test3(
24; CHECK-NEXT:    ret <2 x double> <double 0x100000000, double 0x300000002>
25;
26  %tmp3 = bitcast <4 x i32> < i32 0, i32 1, i32 2, i32 3 > to <2 x double>
27  ret <2 x double> %tmp3
28}
29
30define <4 x float> @test4() {
31; CHECK-LABEL: @test4(
32; CHECK-NEXT:    ret <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0x36A0000000000000, float 0.000000e+00>
33;
34  %tmp3 = bitcast <2 x i64> < i64 0, i64 1 > to <4 x float>
35  ret <4 x float> %tmp3
36}
37
38define <2 x i64> @test5() {
39; CHECK-LABEL: @test5(
40; CHECK-NEXT:    ret <2 x i64> <i64 4575657221408423936, i64 4629700418010611712>
41;
42  %tmp3 = bitcast <4 x float> <float 0.0, float 1.0, float 2.0, float 3.0> to <2 x i64>
43  ret <2 x i64> %tmp3
44}
45
46define <4 x i32> @test6() {
47; CHECK-LABEL: @test6(
48; CHECK-NEXT:    ret <4 x i32> <i32 0, i32 1071644672, i32 0, i32 1072693248>
49;
50  %tmp3 = bitcast <2 x double> <double 0.5, double 1.0> to <4 x i32>
51  ret <4 x i32> %tmp3
52}
53
54define i32 @test7() {
55; CHECK-LABEL: @test7(
56; CHECK-NEXT:    ret i32 1118464
57;
58  %tmp3 = bitcast <2 x half> <half 0xH1100, half 0xH0011> to i32
59  ret i32 %tmp3
60}
61
62define <4 x i32> @test8(<1 x i64> %y) {
63; CHECK-LABEL: @test8(
64; CHECK-NEXT:    ret <4 x i32> zeroinitializer
65;
66  %c = bitcast <2 x i64> <i64 0, i64 0> to <4 x i32>
67  ret <4 x i32> %c
68}
69
70define <4 x i32> @test9(<1 x i64> %y) {
71; CHECK-LABEL: @test9(
72; CHECK-NEXT:    ret <4 x i32> splat (i32 -1)
73;
74  %c = bitcast <2 x i64> <i64 -1, i64 -1> to <4 x i32>
75  ret <4 x i32> %c
76}
77
78define <1 x i1> @test10() {
79; CHECK-LABEL: @test10(
80; CHECK-NEXT:    ret <1 x i1> zeroinitializer
81;
82  %ret = icmp eq <1 x i64> <i64 bitcast (<1 x double> <double 0xFFFFFFFFFFFFFFFF> to i64)>, zeroinitializer
83  ret <1 x i1> %ret
84}
85
86; from MultiSource/Benchmarks/Bullet
87define <2 x float> @foo() {
88; CHECK-LABEL: @foo(
89; CHECK-NEXT:    ret <2 x float> splat (float 0xFFFFFFFFE0000000)
90;
91  %cast = bitcast i64 -1 to <2 x float>
92  ret <2 x float> %cast
93}
94
95
96define <2 x double> @foo2() {
97; CHECK-LABEL: @foo2(
98; CHECK-NEXT:    ret <2 x double> splat (double 0xFFFFFFFFFFFFFFFF)
99;
100  %cast = bitcast i128 -1 to <2 x double>
101  ret <2 x double> %cast
102}
103
104define <1 x float> @foo3() {
105; CHECK-LABEL: @foo3(
106; CHECK-NEXT:    ret <1 x float> splat (float 0xFFFFFFFFE0000000)
107;
108  %cast = bitcast i32 -1 to <1 x float>
109  ret <1 x float> %cast
110}
111
112define float @foo4() {
113; CHECK-LABEL: @foo4(
114; CHECK-NEXT:    ret float 0xFFFFFFFFE0000000
115;
116  %cast = bitcast <1 x i32 ><i32 -1> to float
117  ret float %cast
118}
119
120define double @foo5() {
121; CHECK-LABEL: @foo5(
122; CHECK-NEXT:    ret double 0xFFFFFFFFFFFFFFFF
123;
124  %cast = bitcast <2 x i32 ><i32 -1, i32 -1> to double
125  ret double %cast
126}
127
128define <2 x double> @foo6() {
129; CHECK-LABEL: @foo6(
130; CHECK-NEXT:    ret <2 x double> splat (double 0xFFFFFFFFFFFFFFFF)
131;
132  %cast = bitcast <4 x i32><i32 -1, i32 -1, i32 -1, i32 -1> to <2 x double>
133  ret <2 x double> %cast
134}
135
136define <4 x i32> @bitcast_constexpr_4i32_2i64_u2() {
137; CHECK-LABEL: @bitcast_constexpr_4i32_2i64_u2(
138; CHECK-NEXT:    ret <4 x i32> <i32 undef, i32 undef, i32 2, i32 0>
139;
140  %cast = bitcast <2 x i64><i64 undef, i64 2> to <4 x i32>
141  ret <4 x i32> %cast
142}
143
144define <4 x i32> @bitcast_constexpr_4i32_2i64_1u() {
145; CHECK-LABEL: @bitcast_constexpr_4i32_2i64_1u(
146; CHECK-NEXT:    ret <4 x i32> <i32 1, i32 0, i32 undef, i32 undef>
147;
148  %cast = bitcast <2 x i64><i64 1, i64 undef> to <4 x i32>
149  ret <4 x i32> %cast
150}
151
152define <4 x i32> @bitcast_constexpr_4i32_2i64() {
153; CHECK-LABEL: @bitcast_constexpr_4i32_2i64(
154; CHECK-NEXT:    ret <4 x i32> <i32 undef, i32 undef, i32 2, i32 0>
155;
156  %cast = bitcast <2 x i64><i64 undef, i64 2> to <4 x i32>
157  ret <4 x i32> %cast
158}
159
160define <8 x i16> @bitcast_constexpr_8i16_2i64_u2() {
161; CHECK-LABEL: @bitcast_constexpr_8i16_2i64_u2(
162; CHECK-NEXT:    ret <8 x i16> <i16 undef, i16 undef, i16 undef, i16 undef, i16 2, i16 0, i16 0, i16 0>
163;
164  %cast = bitcast <2 x i64><i64 undef, i64 2> to <8 x i16>
165  ret <8 x i16> %cast
166}
167
168define <8 x i16> @bitcast_constexpr_8i16_2i64_1u() {
169; CHECK-LABEL: @bitcast_constexpr_8i16_2i64_1u(
170; CHECK-NEXT:    ret <8 x i16> <i16 1, i16 0, i16 0, i16 0, i16 undef, i16 undef, i16 undef, i16 undef>
171;
172  %cast = bitcast <2 x i64><i64 1, i64 undef> to <8 x i16>
173  ret <8 x i16> %cast
174}
175
176define <8 x i16> @bitcast_constexpr_8i16_2i64_u65536() {
177; CHECK-LABEL: @bitcast_constexpr_8i16_2i64_u65536(
178; CHECK-NEXT:    ret <8 x i16> <i16 undef, i16 undef, i16 undef, i16 undef, i16 0, i16 1, i16 0, i16 0>
179;
180  %cast = bitcast <2 x i64><i64 undef, i64 65536> to <8 x i16>
181  ret <8 x i16> %cast
182}
183
184define <16 x i8> @bitcast_constexpr_16i8_2i64_u2() {
185; CHECK-LABEL: @bitcast_constexpr_16i8_2i64_u2(
186; CHECK-NEXT:    ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 2, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>
187;
188  %cast = bitcast <2 x i64><i64 undef, i64 2> to <16 x i8>
189  ret <16 x i8> %cast
190}
191
192define <16 x i8> @bitcast_constexpr_16i8_2i64_256u() {
193; CHECK-LABEL: @bitcast_constexpr_16i8_2i64_256u(
194; CHECK-NEXT:    ret <16 x i8> <i8 0, i8 1, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef>
195;
196  %cast = bitcast <2 x i64><i64 256, i64 undef> to <16 x i8>
197  ret <16 x i8> %cast
198}
199
200define <16 x i8> @bitcast_constexpr_16i8_2i64_u256() {
201; CHECK-LABEL: @bitcast_constexpr_16i8_2i64_u256(
202; CHECK-NEXT:    ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 1, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>
203;
204  %cast = bitcast <2 x i64><i64 undef, i64 256> to <16 x i8>
205  ret <16 x i8> %cast
206}
207
208define <8 x i16> @bitcast_constexpr_8i16_4i32_uu22() {
209; CHECK-LABEL: @bitcast_constexpr_8i16_4i32_uu22(
210; CHECK-NEXT:    ret <8 x i16> <i16 undef, i16 undef, i16 undef, i16 undef, i16 2, i16 0, i16 2, i16 0>
211;
212  %cast = bitcast <4 x i32><i32 undef, i32 undef, i32 2, i32 2> to <8 x i16>
213  ret <8 x i16> %cast
214}
215
216define <8 x i16> @bitcast_constexpr_8i16_4i32_10uu() {
217; CHECK-LABEL: @bitcast_constexpr_8i16_4i32_10uu(
218; CHECK-NEXT:    ret <8 x i16> <i16 1, i16 0, i16 0, i16 0, i16 undef, i16 undef, i16 undef, i16 undef>
219;
220  %cast = bitcast <4 x i32><i32 1, i32 0, i32 undef, i32 undef> to <8 x i16>
221  ret <8 x i16> %cast
222}
223
224define <8 x i16> @bitcast_constexpr_8i16_4i32_u257u256() {
225; CHECK-LABEL: @bitcast_constexpr_8i16_4i32_u257u256(
226; CHECK-NEXT:    ret <8 x i16> <i16 undef, i16 undef, i16 0, i16 1, i16 undef, i16 undef, i16 0, i16 1>
227;
228  %cast = bitcast <4 x i32><i32 undef, i32 65536, i32 undef, i32 65536> to <8 x i16>
229  ret <8 x i16> %cast
230}
231
232define <16 x i8> @bitcast_constexpr_16i8_4i32_u2u2() {
233; CHECK-LABEL: @bitcast_constexpr_16i8_4i32_u2u2(
234; CHECK-NEXT:    ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 2, i8 0, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 2, i8 0, i8 0, i8 0>
235;
236  %cast = bitcast <4 x i32><i32 undef, i32 2, i32 undef, i32 2> to <16 x i8>
237  ret <16 x i8> %cast
238}
239
240define <16 x i8> @bitcast_constexpr_16i8_4i32_1u1u() {
241; CHECK-LABEL: @bitcast_constexpr_16i8_4i32_1u1u(
242; CHECK-NEXT:    ret <16 x i8> <i8 1, i8 0, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 1, i8 0, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef>
243;
244  %cast = bitcast <4 x i32><i32 1, i32 undef, i32 1, i32 undef> to <16 x i8>
245  ret <16 x i8> %cast
246}
247
248define <16 x i8> @bitcast_constexpr_16i8_4i32_u256uu() {
249; CHECK-LABEL: @bitcast_constexpr_16i8_4i32_u256uu(
250; CHECK-NEXT:    ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 1, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef>
251;
252  %cast = bitcast <4 x i32><i32 undef, i32 256, i32 undef, i32 undef> to <16 x i8>
253  ret <16 x i8> %cast
254}
255
256define <16 x i8> @bitcast_constexpr_16i8_8i16_u2u2u2u2() {
257; CHECK-LABEL: @bitcast_constexpr_16i8_8i16_u2u2u2u2(
258; CHECK-NEXT:    ret <16 x i8> <i8 undef, i8 undef, i8 2, i8 0, i8 undef, i8 undef, i8 2, i8 0, i8 undef, i8 undef, i8 2, i8 0, i8 undef, i8 undef, i8 2, i8 0>
259;
260  %cast = bitcast <8 x i16><i16 undef, i16 2, i16 undef, i16 2, i16 undef, i16 2, i16 undef, i16 2> to <16 x i8>
261  ret <16 x i8> %cast
262}
263
264define <16 x i8> @bitcast_constexpr_16i8_8i16_1u1u1u1u() {
265; CHECK-LABEL: @bitcast_constexpr_16i8_8i16_1u1u1u1u(
266; CHECK-NEXT:    ret <16 x i8> <i8 1, i8 0, i8 undef, i8 undef, i8 1, i8 0, i8 undef, i8 undef, i8 1, i8 0, i8 undef, i8 undef, i8 1, i8 0, i8 undef, i8 undef>
267;
268  %cast = bitcast <8 x i16><i16 1, i16 undef, i16 1, i16 undef, i16 1, i16 undef, i16 1, i16 undef> to <16 x i8>
269  ret <16 x i8> %cast
270}
271
272define <16 x i8> @bitcast_constexpr_16i8_8i16_u256uuu256uu() {
273; CHECK-LABEL: @bitcast_constexpr_16i8_8i16_u256uuu256uu(
274; CHECK-NEXT:    ret <16 x i8> <i8 undef, i8 undef, i8 0, i8 1, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 1, i8 undef, i8 undef, i8 undef, i8 undef>
275;
276  %cast = bitcast <8 x i16><i16 undef, i16 256, i16 undef, i16 undef, i16 undef, i16 256, i16 undef, i16 undef> to <16 x i8>
277  ret <16 x i8> %cast
278}
279
280define <1 x i32> @bitcast_constexpr_scalar_fp_to_vector_int() {
281; CHECK-LABEL: @bitcast_constexpr_scalar_fp_to_vector_int(
282; CHECK-NEXT:    ret <1 x i32> splat (i32 1065353216)
283;
284  %res = bitcast float 1.0 to <1 x i32>
285  ret <1 x i32> %res
286}
287
288define <2 x i64> @bitcast_constexpr_4f32_2i64_1111() {
289; CHECK-LABEL: @bitcast_constexpr_4f32_2i64_1111(
290; CHECK-NEXT:    ret <2 x i64> splat (i64 4575657222473777152)
291;
292  %res = bitcast <4 x float> splat (float 1.0) to <2 x i64>
293  ret <2 x i64> %res
294}
295