xref: /llvm-project/llvm/test/Transforms/InstCombine/shuffle-cast.ll (revision a5f34155339b4c01357462da95aac62291ed7ec8)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instcombine -S -data-layout="e" | FileCheck %s --check-prefixes=ANY,LE
3; RUN: opt < %s -passes=instcombine -S -data-layout="E" | FileCheck %s --check-prefixes=ANY,BE
4
5define <4 x i16> @trunc_little_endian(<4 x i32> %x) {
6; LE-LABEL: @trunc_little_endian(
7; LE-NEXT:    [[R:%.*]] = trunc <4 x i32> [[X:%.*]] to <4 x i16>
8; LE-NEXT:    ret <4 x i16> [[R]]
9;
10; BE-LABEL: @trunc_little_endian(
11; BE-NEXT:    [[B:%.*]] = bitcast <4 x i32> [[X:%.*]] to <8 x i16>
12; BE-NEXT:    [[R:%.*]] = shufflevector <8 x i16> [[B]], <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
13; BE-NEXT:    ret <4 x i16> [[R]]
14;
15  %b = bitcast <4 x i32> %x to <8 x i16>
16  %r = shufflevector <8 x i16> %b, <8 x i16> undef, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
17  ret <4 x i16> %r
18}
19
20define <4 x i16> @trunc_big_endian(<4 x i32> %x) {
21; LE-LABEL: @trunc_big_endian(
22; LE-NEXT:    [[B:%.*]] = bitcast <4 x i32> [[X:%.*]] to <8 x i16>
23; LE-NEXT:    [[R:%.*]] = shufflevector <8 x i16> [[B]], <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
24; LE-NEXT:    ret <4 x i16> [[R]]
25;
26; BE-LABEL: @trunc_big_endian(
27; BE-NEXT:    [[R:%.*]] = trunc <4 x i32> [[X:%.*]] to <4 x i16>
28; BE-NEXT:    ret <4 x i16> [[R]]
29;
30  %b = bitcast <4 x i32> %x to <8 x i16>
31  %r = shufflevector <8 x i16> %b, <8 x i16> undef, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
32  ret <4 x i16> %r
33}
34
35declare void @use_v8i16(<8 x i16>)
36
37; Extra use is ok.
38
39define <2 x i16> @trunc_little_endian_extra_use(<2 x i64> %x) {
40; LE-LABEL: @trunc_little_endian_extra_use(
41; LE-NEXT:    [[B:%.*]] = bitcast <2 x i64> [[X:%.*]] to <8 x i16>
42; LE-NEXT:    call void @use_v8i16(<8 x i16> [[B]])
43; LE-NEXT:    [[R:%.*]] = trunc <2 x i64> [[X]] to <2 x i16>
44; LE-NEXT:    ret <2 x i16> [[R]]
45;
46; BE-LABEL: @trunc_little_endian_extra_use(
47; BE-NEXT:    [[B:%.*]] = bitcast <2 x i64> [[X:%.*]] to <8 x i16>
48; BE-NEXT:    call void @use_v8i16(<8 x i16> [[B]])
49; BE-NEXT:    [[R:%.*]] = shufflevector <8 x i16> [[B]], <8 x i16> poison, <2 x i32> <i32 0, i32 4>
50; BE-NEXT:    ret <2 x i16> [[R]]
51;
52  %b = bitcast <2 x i64> %x to <8 x i16>
53  call void @use_v8i16(<8 x i16> %b)
54  %r = shufflevector <8 x i16> %b, <8 x i16> undef, <2 x i32> <i32 0, i32 4>
55  ret <2 x i16> %r
56}
57
58declare void @use_v12i11(<12 x i11>)
59
60; Weird types are ok.
61
62define <4 x i11> @trunc_big_endian_extra_use(<4 x i33> %x) {
63; LE-LABEL: @trunc_big_endian_extra_use(
64; LE-NEXT:    [[B:%.*]] = bitcast <4 x i33> [[X:%.*]] to <12 x i11>
65; LE-NEXT:    call void @use_v12i11(<12 x i11> [[B]])
66; LE-NEXT:    [[R:%.*]] = shufflevector <12 x i11> [[B]], <12 x i11> poison, <4 x i32> <i32 2, i32 5, i32 8, i32 11>
67; LE-NEXT:    ret <4 x i11> [[R]]
68;
69; BE-LABEL: @trunc_big_endian_extra_use(
70; BE-NEXT:    [[B:%.*]] = bitcast <4 x i33> [[X:%.*]] to <12 x i11>
71; BE-NEXT:    call void @use_v12i11(<12 x i11> [[B]])
72; BE-NEXT:    [[R:%.*]] = trunc <4 x i33> [[X]] to <4 x i11>
73; BE-NEXT:    ret <4 x i11> [[R]]
74;
75  %b = bitcast <4 x i33> %x to <12 x i11>
76  call void @use_v12i11(<12 x i11> %b)
77  %r = shufflevector <12 x i11> %b, <12 x i11> undef, <4 x i32> <i32 2, i32 5, i32 8, i32 11>
78  ret <4 x i11> %r
79}
80
81define <4 x i16> @wrong_cast1(i128 %x) {
82; ANY-LABEL: @wrong_cast1(
83; ANY-NEXT:    [[B:%.*]] = bitcast i128 [[X:%.*]] to <8 x i16>
84; ANY-NEXT:    [[R:%.*]] = shufflevector <8 x i16> [[B]], <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
85; ANY-NEXT:    ret <4 x i16> [[R]]
86;
87  %b = bitcast i128 %x to <8 x i16>
88  %r = shufflevector <8 x i16> %b, <8 x i16> undef, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
89  ret <4 x i16> %r
90}
91
92define <4 x i16> @wrong_cast2(<4 x float> %x) {
93; ANY-LABEL: @wrong_cast2(
94; ANY-NEXT:    [[B:%.*]] = bitcast <4 x float> [[X:%.*]] to <8 x i16>
95; ANY-NEXT:    [[R:%.*]] = shufflevector <8 x i16> [[B]], <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
96; ANY-NEXT:    ret <4 x i16> [[R]]
97;
98  %b = bitcast <4 x float> %x to <8 x i16>
99  %r = shufflevector <8 x i16> %b, <8 x i16> undef, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
100  ret <4 x i16> %r
101}
102
103define <4 x half> @wrong_cast3(<4 x i32> %x) {
104; ANY-LABEL: @wrong_cast3(
105; ANY-NEXT:    [[B:%.*]] = bitcast <4 x i32> [[X:%.*]] to <8 x half>
106; ANY-NEXT:    [[R:%.*]] = shufflevector <8 x half> [[B]], <8 x half> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
107; ANY-NEXT:    ret <4 x half> [[R]]
108;
109  %b = bitcast <4 x i32> %x to <8 x half>
110  %r = shufflevector <8 x half> %b, <8 x half> undef, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
111  ret <4 x half> %r
112}
113
114define <2 x i16> @wrong_shuffle(<4 x i32> %x) {
115; ANY-LABEL: @wrong_shuffle(
116; ANY-NEXT:    [[B:%.*]] = bitcast <4 x i32> [[X:%.*]] to <8 x i16>
117; ANY-NEXT:    [[R:%.*]] = shufflevector <8 x i16> [[B]], <8 x i16> poison, <2 x i32> <i32 0, i32 2>
118; ANY-NEXT:    ret <2 x i16> [[R]]
119;
120  %b = bitcast <4 x i32> %x to <8 x i16>
121  %r = shufflevector <8 x i16> %b, <8 x i16> undef, <2 x i32> <i32 0, i32 2>
122  ret <2 x i16> %r
123}
124