1 // RUN: %clang_cc1 -ffreestanding %s -O3 -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,X64
2 // RUN: %clang_cc1 -ffreestanding %s -O3 -triple=i386-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,X86
3 // FIXME: This is testing optimized generation of shuffle instructions and should be fixed.
9 // Test LLVM IR codegen of shuffle instructions, checking if the masks are correct
12 __m256
x(__m256 a
, __m256 b
) {
14 // CHECK: shufflevector{{.*}}<i32 3, i32 2, i32 8, i32 11, i32 7, i32 6, i32 12, i32 15>
15 return _mm256_shuffle_ps(a
, b
, 203);
18 __m128d
test_mm_permute_pd(__m128d a
) {
19 // CHECK-LABEL: test_mm_permute_pd
20 // CHECK: shufflevector{{.*}}<i32 1, i32 0>
21 return _mm_permute_pd(a
, 1);
24 __m256d
test_mm256_permute_pd(__m256d a
) {
25 // CHECK-LABEL: test_mm256_permute_pd
26 // CHECK: shufflevector{{.*}}<i32 1, i32 0, i32 3, i32 2>
27 return _mm256_permute_pd(a
, 5);
30 __m128
test_mm_permute_ps(__m128 a
) {
31 // CHECK-LABEL: test_mm_permute_ps
32 // CHECK: shufflevector{{.*}}<i32 3, i32 2, i32 1, i32 0>
33 return _mm_permute_ps(a
, 0x1b);
36 // Test case for PR12401
37 __m128
test_mm_permute_ps2(__m128 a
) {
38 // CHECK-LABEL: test_mm_permute_ps2
39 // CHECK: shufflevector{{.*}}<i32 2, i32 1, i32 2, i32 3>
40 return _mm_permute_ps(a
, 0xe6);
43 __m256
test_mm256_permute_ps(__m256 a
) {
44 // CHECK-LABEL: test_mm256_permute_ps
45 // CHECK: shufflevector{{.*}}<i32 3, i32 2, i32 1, i32 0, i32 7, i32 6, i32 5, i32 4>
46 return _mm256_permute_ps(a
, 0x1b);
49 __m256d
test_mm256_permute2f128_pd(__m256d a
, __m256d b
) {
50 // CHECK-LABEL: test_mm256_permute2f128_pd
51 // CHECK: shufflevector{{.*}}<i32 2, i32 3, i32 6, i32 7>
52 return _mm256_permute2f128_pd(a
, b
, 0x31);
55 __m256
test_mm256_permute2f128_ps(__m256 a
, __m256 b
) {
56 // CHECK-LABEL: test_mm256_permute2f128_ps
57 // CHECK: shufflevector{{.*}}<i32 4, i32 5, i32 6, i32 7, i32 12, i32 13, i32 14, i32 15>
58 return _mm256_permute2f128_ps(a
, b
, 0x13);
61 __m256i
test_mm256_permute2f128_si256(__m256i a
, __m256i b
) {
62 // CHECK-LABEL: test_mm256_permute2f128_si256
63 // CHECK: shufflevector{{.*}} <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11>
64 return _mm256_permute2f128_si256(a
, b
, 0x20);
68 test_mm_broadcast_ss(float const *__a
) {
69 // CHECK-LABEL: test_mm_broadcast_ss
70 // CHECK: insertelement <4 x float> {{.*}}, i64 0
71 // CHECK: shufflevector <4 x float> {{.*}}, <4 x float> poison, <4 x i32> zeroinitializer
72 return _mm_broadcast_ss(__a
);
76 test_mm256_broadcast_sd(double const *__a
) {
77 // CHECK-LABEL: test_mm256_broadcast_sd
78 // CHECK: insertelement <4 x double> {{.*}}, i64 0
79 // CHECK: shufflevector <4 x double> {{.*}}, <4 x double> poison, <4 x i32> zeroinitializer
80 return _mm256_broadcast_sd(__a
);
84 test_mm256_broadcast_ss(float const *__a
) {
85 // CHECK-LABEL: test_mm256_broadcast_ss
86 // CHECK: insertelement <8 x float> {{.*}}, i64 0
87 // CHECK: shufflevector <8 x float> {{.*}}, <8 x float> poison, <8 x i32> zeroinitializer
88 return _mm256_broadcast_ss(__a
);
91 // Make sure we have the correct mask for each insertf128 case.
93 __m256
test_mm256_insertf128_ps_0(__m256 a
, __m128 b
) {
94 // CHECK-LABEL: test_mm256_insertf128_ps_0
95 // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3, i32 12, i32 13, i32 14, i32 15>
96 return _mm256_insertf128_ps(a
, b
, 0);
99 __m256d
test_mm256_insertf128_pd_0(__m256d a
, __m128d b
) {
100 // CHECK-LABEL: test_mm256_insertf128_pd_0
101 // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 6, i32 7>
102 return _mm256_insertf128_pd(a
, b
, 0);
105 __m256i
test_mm256_insertf128_si256_0(__m256i a
, __m128i b
) {
106 // CHECK-LABEL: test_mm256_insertf128_si256_0
107 // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3, i32 12, i32 13, i32 14, i32 15>
108 return _mm256_insertf128_si256(a
, b
, 0);
111 __m256
test_mm256_insertf128_ps_1(__m256 a
, __m128 b
) {
112 // CHECK-LABEL: test_mm256_insertf128_ps_1
113 // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11>
114 return _mm256_insertf128_ps(a
, b
, 1);
117 __m256d
test_mm256_insertf128_pd_1(__m256d a
, __m128d b
) {
118 // CHECK-LABEL: test_mm256_insertf128_pd_1
119 // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 4, i32 5>
120 return _mm256_insertf128_pd(a
, b
, 1);
123 __m256i
test_mm256_insertf128_si256_1(__m256i a
, __m128i b
) {
124 // CHECK-LABEL: test_mm256_insertf128_si256_1
125 // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11>
126 return _mm256_insertf128_si256(a
, b
, 1);
129 // Make sure we have the correct mask for each extractf128 case.
131 __m128
test_mm256_extractf128_ps_0(__m256 a
) {
132 // X64-LABEL: test_mm256_extractf128_ps_0
133 // X64: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3>
135 // X86-LABEL: test_mm256_extractf128_ps_0
136 // X86: shufflevector{{.*}}<i32 0, i32 1>
137 return _mm256_extractf128_ps(a
, 0);
140 __m128d
test_mm256_extractf128_pd_0(__m256d a
) {
141 // CHECK-LABEL: test_mm256_extractf128_pd_0
142 // CHECK: shufflevector{{.*}}<i32 0, i32 1>
143 return _mm256_extractf128_pd(a
, 0);
146 __m128i
test_mm256_extractf128_si256_0(__m256i a
) {
147 // CHECK-LABEL: test_mm256_extractf128_si256_0
148 // CHECK: shufflevector{{.*}}<i32 0, i32 1>
149 return _mm256_extractf128_si256(a
, 0);
152 __m128
test_mm256_extractf128_ps_1(__m256 a
) {
153 // X64-LABEL: test_mm256_extractf128_ps_1
154 // X64: shufflevector{{.*}}<i32 4, i32 5, i32 6, i32 7>
156 // X86-LABEL: test_mm256_extractf128_ps_1
157 // X86: shufflevector{{.*}}<i32 2, i32 3>
158 return _mm256_extractf128_ps(a
, 1);
161 __m128d
test_mm256_extractf128_pd_1(__m256d a
) {
162 // CHECK-LABEL: test_mm256_extractf128_pd_1
163 // CHECK: shufflevector{{.*}}<i32 2, i32 3>
164 return _mm256_extractf128_pd(a
, 1);
167 __m128i
test_mm256_extractf128_si256_1(__m256i a
) {
168 // CHECK-LABEL: test_mm256_extractf128_si256_1
169 // CHECK: shufflevector{{.*}}<i32 2, i32 3>
170 return _mm256_extractf128_si256(a
, 1);
173 __m256
test_mm256_set_m128(__m128 hi
, __m128 lo
) {
174 // CHECK-LABEL: test_mm256_set_m128
175 // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
176 return _mm256_set_m128(hi
, lo
);
179 __m256d
test_mm256_set_m128d(__m128d hi
, __m128d lo
) {
180 // CHECK-LABEL: test_mm256_set_m128d
181 // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3>
182 return _mm256_set_m128d(hi
, lo
);
185 __m256i
test_mm256_set_m128i(__m128i hi
, __m128i lo
) {
186 // CHECK-LABEL: test_mm256_set_m128i
187 // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3>
188 return _mm256_set_m128i(hi
, lo
);
191 __m256
test_mm256_setr_m128(__m128 hi
, __m128 lo
) {
192 // CHECK-LABEL: test_mm256_setr_m128
193 // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
194 return _mm256_setr_m128(lo
, hi
);
197 __m256d
test_mm256_setr_m128d(__m128d hi
, __m128d lo
) {
198 // CHECK-LABEL: test_mm256_setr_m128d
199 // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3>
200 return _mm256_setr_m128d(lo
, hi
);
203 __m256i
test_mm256_setr_m128i(__m128i hi
, __m128i lo
) {
204 // CHECK-LABEL: test_mm256_setr_m128i
205 // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3>
206 return _mm256_setr_m128i(lo
, hi
);