Skip to content

Commit c84446f

Browse files
committed
[VectorCombine] add tests for bitcast (shuffle); NFC
1 parent 6b6a779 commit c84446f

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -vector-combine -S -mtriple=x86_64-- -mattr=SSE2 | FileCheck %s --check-prefixes=CHECK,SSE
3+
; RUN: opt < %s -vector-combine -S -mtriple=x86_64-- -mattr=AVX2 | FileCheck %s --check-prefixes=CHECK,AVX
4+
5+
define <16 x i8> @bitcast_shuf_narrow_element(<4 x i32> %v) {
6+
; CHECK-LABEL: @bitcast_shuf_narrow_element(
7+
; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[V:%.*]], <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
8+
; CHECK-NEXT: [[R:%.*]] = bitcast <4 x i32> [[SHUF]] to <16 x i8>
9+
; CHECK-NEXT: ret <16 x i8> [[R]]
10+
;
11+
%shuf = shufflevector <4 x i32> %v, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
12+
%r = bitcast <4 x i32> %shuf to <16 x i8>
13+
ret <16 x i8> %r
14+
}
15+
16+
define <4 x float> @bitcast_shuf_same_size(<4 x i32> %v) {
17+
; CHECK-LABEL: @bitcast_shuf_same_size(
18+
; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[V:%.*]], <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
19+
; CHECK-NEXT: [[R:%.*]] = bitcast <4 x i32> [[SHUF]] to <4 x float>
20+
; CHECK-NEXT: ret <4 x float> [[R]]
21+
;
22+
%shuf = shufflevector <4 x i32> %v, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
23+
%r = bitcast <4 x i32> %shuf to <4 x float>
24+
ret <4 x float> %r
25+
}
26+
27+
define <4 x i32> @bitcast_shuf_wide_element(<8 x i16> %v) {
28+
; CHECK-LABEL: @bitcast_shuf_wide_element(
29+
; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <8 x i16> [[V:%.*]], <8 x i16> undef, <8 x i32> <i32 0, i32 1, i32 0, i32 1, i32 2, i32 3, i32 2, i32 3>
30+
; CHECK-NEXT: [[R:%.*]] = bitcast <8 x i16> [[SHUF]] to <4 x i32>
31+
; CHECK-NEXT: ret <4 x i32> [[R]]
32+
;
33+
%shuf = shufflevector <8 x i16> %v, <8 x i16> undef, <8 x i32> <i32 0, i32 1, i32 0, i32 1, i32 2, i32 3, i32 2, i32 3>
34+
%r = bitcast <8 x i16> %shuf to <4 x i32>
35+
ret <4 x i32> %r
36+
}
37+
38+
declare void @use(<4 x i32>)
39+
40+
define <16 x i8> @bitcast_shuf_uses(<4 x i32> %v) {
41+
; CHECK-LABEL: @bitcast_shuf_uses(
42+
; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[V:%.*]], <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
43+
; CHECK-NEXT: call void @use(<4 x i32> [[SHUF]])
44+
; CHECK-NEXT: [[R:%.*]] = bitcast <4 x i32> [[SHUF]] to <16 x i8>
45+
; CHECK-NEXT: ret <16 x i8> [[R]]
46+
;
47+
%shuf = shufflevector <4 x i32> %v, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
48+
call void @use(<4 x i32> %shuf)
49+
%r = bitcast <4 x i32> %shuf to <16 x i8>
50+
ret <16 x i8> %r
51+
}
52+
53+
define <2 x i64> @PR35454_1(<2 x i64> %v) {
54+
; CHECK-LABEL: @PR35454_1(
55+
; CHECK-NEXT: [[BC:%.*]] = bitcast <2 x i64> [[V:%.*]] to <4 x i32>
56+
; CHECK-NEXT: [[PERMIL:%.*]] = shufflevector <4 x i32> [[BC]], <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
57+
; CHECK-NEXT: [[BC1:%.*]] = bitcast <4 x i32> [[PERMIL]] to <16 x i8>
58+
; CHECK-NEXT: [[ADD:%.*]] = shl <16 x i8> [[BC1]], <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
59+
; CHECK-NEXT: [[BC2:%.*]] = bitcast <16 x i8> [[ADD]] to <4 x i32>
60+
; CHECK-NEXT: [[PERMIL1:%.*]] = shufflevector <4 x i32> [[BC2]], <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
61+
; CHECK-NEXT: [[BC3:%.*]] = bitcast <4 x i32> [[PERMIL1]] to <2 x i64>
62+
; CHECK-NEXT: ret <2 x i64> [[BC3]]
63+
;
64+
%bc = bitcast <2 x i64> %v to <4 x i32>
65+
%permil = shufflevector <4 x i32> %bc, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
66+
%bc1 = bitcast <4 x i32> %permil to <16 x i8>
67+
%add = shl <16 x i8> %bc1, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
68+
%bc2 = bitcast <16 x i8> %add to <4 x i32>
69+
%permil1 = shufflevector <4 x i32> %bc2, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
70+
%bc3 = bitcast <4 x i32> %permil1 to <2 x i64>
71+
ret <2 x i64> %bc3
72+
}
73+
74+
define <2 x i64> @PR35454_2(<2 x i64> %v) {
75+
; CHECK-LABEL: @PR35454_2(
76+
; CHECK-NEXT: [[BC:%.*]] = bitcast <2 x i64> [[V:%.*]] to <4 x i32>
77+
; CHECK-NEXT: [[PERMIL:%.*]] = shufflevector <4 x i32> [[BC]], <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
78+
; CHECK-NEXT: [[BC1:%.*]] = bitcast <4 x i32> [[PERMIL]] to <8 x i16>
79+
; CHECK-NEXT: [[ADD:%.*]] = shl <8 x i16> [[BC1]], <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
80+
; CHECK-NEXT: [[BC2:%.*]] = bitcast <8 x i16> [[ADD]] to <4 x i32>
81+
; CHECK-NEXT: [[PERMIL1:%.*]] = shufflevector <4 x i32> [[BC2]], <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
82+
; CHECK-NEXT: [[BC3:%.*]] = bitcast <4 x i32> [[PERMIL1]] to <2 x i64>
83+
; CHECK-NEXT: ret <2 x i64> [[BC3]]
84+
;
85+
%bc = bitcast <2 x i64> %v to <4 x i32>
86+
%permil = shufflevector <4 x i32> %bc, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
87+
%bc1 = bitcast <4 x i32> %permil to <8 x i16>
88+
%add = shl <8 x i16> %bc1, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
89+
%bc2 = bitcast <8 x i16> %add to <4 x i32>
90+
%permil1 = shufflevector <4 x i32> %bc2, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
91+
%bc3 = bitcast <4 x i32> %permil1 to <2 x i64>
92+
ret <2 x i64> %bc3
93+
}

0 commit comments

Comments
 (0)