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
5 define <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]]
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]]
15 %b = bitcast <4 x i32> %x to <8 x i16>
16 %r = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
20 define <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]]
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]]
30 %b = bitcast <4 x i32> %x to <8 x i16>
31 %r = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
35 declare void @use_v8i16(<8 x i16>)
39 define <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]]
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]]
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> poison, <2 x i32> <i32 0, i32 4>
58 declare void @use_v12i11(<12 x i11>)
62 define <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]]
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]]
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> poison, <4 x i32> <i32 2, i32 5, i32 8, i32 11>
81 define <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]]
87 %b = bitcast i128 %x to <8 x i16>
88 %r = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
92 define <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]]
98 %b = bitcast <4 x float> %x to <8 x i16>
99 %r = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
103 define <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]]
109 %b = bitcast <4 x i32> %x to <8 x half>
110 %r = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
114 define <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]]
120 %b = bitcast <4 x i32> %x to <8 x i16>
121 %r = shufflevector <8 x i16> %b, <8 x i16> poison, <2 x i32> <i32 0, i32 2>