AVX-512: added UNPACK instructions and tests for all-zero/all-ones vectors
[oota-llvm.git] / test / CodeGen / X86 / avx512-shuffle.ll
1 ; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=knl | FileCheck %s
2 ; CHECK: LCP
3 ; CHECK: .long 2
4 ; CHECK: .long 5
5 ; CHECK: .long 0
6 ; CHECK: .long 0
7 ; CHECK: .long 7
8 ; CHECK: .long 0
9 ; CHECK: .long 10
10 ; CHECK: .long 1
11 ; CHECK: .long 0
12 ; CHECK: .long 5
13 ; CHECK: .long 0
14 ; CHECK: .long 4
15 ; CHECK: .long 7
16 ; CHECK: .long 0
17 ; CHECK: .long 10
18 ; CHECK: .long 1
19 ; CHECK-LABEL: test1:
20 ; CHECK: vpermps
21 ; CHECK: ret
22 define <16 x float> @test1(<16 x float> %a) nounwind {
23   %c = shufflevector <16 x float> %a, <16 x float> undef, <16 x i32> <i32 2, i32 5, i32 undef, i32 undef, i32 7, i32 undef, i32 10, i32 1,  i32 0, i32 5, i32 undef, i32 4, i32 7, i32 undef, i32 10, i32 1>
24   ret <16 x float> %c
25 }
26
27 ; CHECK-LABEL: test2:
28 ; CHECK: vpermd
29 ; CHECK: ret
30 define <16 x i32> @test2(<16 x i32> %a) nounwind {
31   %c = shufflevector <16 x i32> %a, <16 x i32> undef, <16 x i32> <i32 2, i32 5, i32 undef, i32 undef, i32 7, i32 undef, i32 10, i32 1,  i32 0, i32 5, i32 undef, i32 4, i32 7, i32 undef, i32 10, i32 1>
32   ret <16 x i32> %c
33 }
34
35 ; CHECK-LABEL: test3:
36 ; CHECK: vpermq
37 ; CHECK: ret
38 define <8 x i64> @test3(<8 x i64> %a) nounwind {
39   %c = shufflevector <8 x i64> %a, <8 x i64> undef, <8 x i32> <i32 2, i32 5, i32 1, i32 undef, i32 7, i32 undef, i32 3, i32 1>
40   ret <8 x i64> %c
41 }
42
43 ; CHECK-LABEL: test4:
44 ; CHECK: vpermpd
45 ; CHECK: ret
46 define <8 x double> @test4(<8 x double> %a) nounwind {
47   %c = shufflevector <8 x double> %a, <8 x double> undef, <8 x i32> <i32 1, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
48   ret <8 x double> %c
49 }
50
51 ; CHECK-LABEL: test5:
52 ; CHECK: vpermi2pd
53 ; CHECK: ret
54 define <8 x double> @test5(<8 x double> %a, <8 x double> %b) nounwind {
55   %c = shufflevector <8 x double> %a, <8 x double> %b, <8 x i32> <i32 2, i32 8, i32 0, i32 1, i32 6, i32 10, i32 4, i32 5>
56   ret <8 x double> %c
57 }
58
59 ; CHECK-LABEL: test6:
60 ; CHECK: vpermq $30
61 ; CHECK: ret
62 define <8 x i64> @test6(<8 x i64> %a) nounwind {
63   %c = shufflevector <8 x i64> %a, <8 x i64> undef, <8 x i32> <i32 2, i32 3, i32 1, i32 0, i32 6, i32 7, i32 5, i32 4>
64   ret <8 x i64> %c
65 }
66
67 ; CHECK-LABEL: test7:
68 ; CHECK: vpermi2q
69 ; CHECK: ret
70 define <8 x i64> @test7(<8 x i64> %a, <8 x i64> %b) nounwind {
71   %c = shufflevector <8 x i64> %a, <8 x i64> %b, <8 x i32> <i32 2, i32 8, i32 0, i32 1, i32 6, i32 10, i32 4, i32 5>
72   ret <8 x i64> %c
73 }
74
75 ; CHECK-LABEL: test8:
76 ; CHECK: vpermi2d
77 ; CHECK: ret
78 define <16 x i32> @test8(<16 x i32> %a, <16 x i32> %b) nounwind {
79   %c = shufflevector <16 x i32> %a, <16 x i32> %b, <16 x i32> <i32 15, i32 31, i32 14, i32 22, i32 13, i32 29, i32 4, i32 28, i32 11, i32 27, i32 10, i32 26, i32 9, i32 25, i32 8, i32 24>
80   ret <16 x i32> %c
81 }
82
83 ; CHECK-LABEL: test9:
84 ; CHECK: vpermi2ps
85 ; CHECK: ret
86 define <16 x float> @test9(<16 x float> %a, <16 x float> %b) nounwind {
87   %c = shufflevector <16 x float> %a, <16 x float> %b, <16 x i32> <i32 15, i32 31, i32 14, i32 22, i32 13, i32 29, i32 4, i32 28, i32 11, i32 27, i32 10, i32 26, i32 9, i32 25, i32 8, i32 24>
88   ret <16 x float> %c
89 }
90
91 ; CHECK-LABEL: test10:
92 ; CHECK: vpermi2ps (
93 ; CHECK: ret
94 define <16 x float> @test10(<16 x float> %a, <16 x float>* %b) nounwind {
95   %c = load <16 x float>* %b
96   %d = shufflevector <16 x float> %a, <16 x float> %c, <16 x i32> <i32 15, i32 31, i32 14, i32 22, i32 13, i32 29, i32 4, i32 28, i32 11, i32 27, i32 10, i32 26, i32 9, i32 25, i32 8, i32 24>
97   ret <16 x float> %d
98 }
99
100 ; CHECK-LABEL: test11:
101 ; CHECK: vpermi2d (
102 ; CHECK: ret
103 define <16 x i32> @test11(<16 x i32> %a, <16 x i32>* %b) nounwind {
104   %c = load <16 x i32>* %b
105   %d = shufflevector <16 x i32> %a, <16 x i32> %c, <16 x i32> <i32 15, i32 31, i32 14, i32 22, i32 13, i32 29, i32 4, i32 28, i32 11, i32 27, i32 10, i32 26, i32 9, i32 25, i32 8, i32 24>
106   ret <16 x i32> %d
107 }
108
109 ; CHECK-LABEL: test18
110 ; CHECK: vpunpckhdq %zmm
111 ; CHECK: ret
112 define <16 x i32> @test18(<16 x i32> %a, <16 x i32> %c) {
113  %b = shufflevector <16 x i32> %a, <16 x i32> %c, <16 x i32><i32 2, i32 10, i32 3, i32 11, i32 6, i32 14, i32 7, i32 15, i32 18, i32 26, i32 19, i32 27, i32 22, i32 30, i32 23, i32 31>
114  ret <16 x i32> %b
115 }
116
117 ; CHECK-LABEL: test19
118 ; CHECK: vpunpckldq %zmm
119 ; CHECK: ret
120 define <16 x i32> @test19(<16 x i32> %a, <16 x i32> %c) {
121  %b = shufflevector <16 x i32> %a, <16 x i32> %c, <16 x i32><i32 0, i32 8, i32 1, i32 9, i32 4, i32 12, i32 5, i32 13, i32 16, i32 24, i32 17, i32 25, i32 20, i32 28, i32 21, i32 29>
122  ret <16 x i32> %b
123 }
124
125 ; CHECK-LABEL: test20
126 ; CHECK: vpunpckhqdq  %zmm
127 ; CHECK: ret
128 define <8 x i64> @test20(<8 x i64> %a, <8 x i64> %c) {
129  %b = shufflevector <8 x i64> %a, <8 x i64> %c, <8 x i32><i32 1, i32 5, i32 3, i32 7, i32 9, i32 13, i32 11, i32 15>
130  ret <8 x i64> %b
131 }
132
133 ; CHECK-LABEL: test21
134 ; CHECK: vunpcklps %zmm
135 ; CHECK: ret
136 define <16 x float> @test21(<16 x float> %a, <16 x float> %c) {
137  %b = shufflevector <16 x float> %a, <16 x float> %c, <16 x i32><i32 0, i32 8, i32 1, i32 9, i32 4, i32 12, i32 5, i32 13, i32 16, i32 24, i32 17, i32 25, i32 20, i32 28, i32 21, i32 29>
138  ret <16 x float> %b
139 }
140