1f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -O3 -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s
2f4a2713aSLionel Sambuc
3f4a2713aSLionel Sambuc // Don't include mm_malloc.h, it's system specific.
4f4a2713aSLionel Sambuc #define __MM_MALLOC_H
5f4a2713aSLionel Sambuc
6f4a2713aSLionel Sambuc #include <immintrin.h>
7f4a2713aSLionel Sambuc
8f4a2713aSLionel Sambuc //
9f4a2713aSLionel Sambuc // Test LLVM IR codegen of shuffle instructions
10f4a2713aSLionel Sambuc //
11f4a2713aSLionel Sambuc
x(__m256 a,__m256 b)12f4a2713aSLionel Sambuc __m256 x(__m256 a, __m256 b) {
13f4a2713aSLionel Sambuc // Check if the mask is correct
14f4a2713aSLionel Sambuc // CHECK: shufflevector{{.*}}<i32 3, i32 2, i32 8, i32 11, i32 7, i32 6, i32 12, i32 15>
15f4a2713aSLionel Sambuc return _mm256_shuffle_ps(a, b, 203);
16f4a2713aSLionel Sambuc }
17f4a2713aSLionel Sambuc
test_mm_permute_pd(__m128d a)18f4a2713aSLionel Sambuc __m128d test_mm_permute_pd(__m128d a) {
19f4a2713aSLionel Sambuc // Check if the mask is correct
20f4a2713aSLionel Sambuc // CHECK: shufflevector{{.*}}<i32 1, i32 0>
21f4a2713aSLionel Sambuc return _mm_permute_pd(a, 1);
22f4a2713aSLionel Sambuc }
23f4a2713aSLionel Sambuc
test_mm256_permute_pd(__m256d a)24f4a2713aSLionel Sambuc __m256d test_mm256_permute_pd(__m256d a) {
25f4a2713aSLionel Sambuc // Check if the mask is correct
26f4a2713aSLionel Sambuc // CHECK: shufflevector{{.*}}<i32 1, i32 0, i32 3, i32 2>
27f4a2713aSLionel Sambuc return _mm256_permute_pd(a, 5);
28f4a2713aSLionel Sambuc }
29f4a2713aSLionel Sambuc
test_mm_permute_ps(__m128 a)30f4a2713aSLionel Sambuc __m128 test_mm_permute_ps(__m128 a) {
31f4a2713aSLionel Sambuc // Check if the mask is correct
32f4a2713aSLionel Sambuc // CHECK: shufflevector{{.*}}<i32 3, i32 2, i32 1, i32 0>
33f4a2713aSLionel Sambuc return _mm_permute_ps(a, 0x1b);
34f4a2713aSLionel Sambuc }
35f4a2713aSLionel Sambuc
36f4a2713aSLionel Sambuc // Test case for PR12401
test_mm_permute_ps2(__m128 a)37f4a2713aSLionel Sambuc __m128 test_mm_permute_ps2(__m128 a) {
38f4a2713aSLionel Sambuc // Check if the mask is correct
39f4a2713aSLionel Sambuc // CHECK: shufflevector{{.*}}<i32 2, i32 1, i32 2, i32 3>
40f4a2713aSLionel Sambuc return _mm_permute_ps(a, 0xe6);
41f4a2713aSLionel Sambuc }
42f4a2713aSLionel Sambuc
test_mm256_permute_ps(__m256 a)43f4a2713aSLionel Sambuc __m256 test_mm256_permute_ps(__m256 a) {
44f4a2713aSLionel Sambuc // Check if the mask is correct
45f4a2713aSLionel Sambuc // CHECK: shufflevector{{.*}}<i32 3, i32 2, i32 1, i32 0, i32 7, i32 6, i32 5, i32 4>
46f4a2713aSLionel Sambuc return _mm256_permute_ps(a, 0x1b);
47f4a2713aSLionel Sambuc }
48f4a2713aSLionel Sambuc
test_mm256_permute2f128_pd(__m256d a,__m256d b)49f4a2713aSLionel Sambuc __m256d test_mm256_permute2f128_pd(__m256d a, __m256d b) {
50f4a2713aSLionel Sambuc // Check if the mask is correct
51f4a2713aSLionel Sambuc // CHECK: @llvm.x86.avx.vperm2f128.pd.256
52f4a2713aSLionel Sambuc return _mm256_permute2f128_pd(a, b, 0x31);
53f4a2713aSLionel Sambuc }
54f4a2713aSLionel Sambuc
test_mm256_permute2f128_ps(__m256 a,__m256 b)55f4a2713aSLionel Sambuc __m256 test_mm256_permute2f128_ps(__m256 a, __m256 b) {
56f4a2713aSLionel Sambuc // Check if the mask is correct
57f4a2713aSLionel Sambuc // CHECK: @llvm.x86.avx.vperm2f128.ps.256
58f4a2713aSLionel Sambuc return _mm256_permute2f128_ps(a, b, 0x13);
59f4a2713aSLionel Sambuc }
60f4a2713aSLionel Sambuc
test_mm256_permute2f128_si256(__m256i a,__m256i b)61f4a2713aSLionel Sambuc __m256i test_mm256_permute2f128_si256(__m256i a, __m256i b) {
62f4a2713aSLionel Sambuc // Check if the mask is correct
63f4a2713aSLionel Sambuc // CHECK: @llvm.x86.avx.vperm2f128.si.256
64f4a2713aSLionel Sambuc return _mm256_permute2f128_si256(a, b, 0x20);
65f4a2713aSLionel Sambuc }
66*0a6a1f1dSLionel Sambuc
67*0a6a1f1dSLionel Sambuc __m128
test_mm_broadcast_ss(float const * __a)68*0a6a1f1dSLionel Sambuc test_mm_broadcast_ss(float const *__a) {
69*0a6a1f1dSLionel Sambuc // CHECK-LABEL: @test_mm_broadcast_ss
70*0a6a1f1dSLionel Sambuc // CHECK: insertelement <4 x float> {{.*}}, i32 0
71*0a6a1f1dSLionel Sambuc // CHECK: insertelement <4 x float> {{.*}}, i32 1
72*0a6a1f1dSLionel Sambuc // CHECK: insertelement <4 x float> {{.*}}, i32 2
73*0a6a1f1dSLionel Sambuc // CHECK: insertelement <4 x float> {{.*}}, i32 3
74*0a6a1f1dSLionel Sambuc return _mm_broadcast_ss(__a);
75*0a6a1f1dSLionel Sambuc }
76*0a6a1f1dSLionel Sambuc
77*0a6a1f1dSLionel Sambuc __m256d
test_mm256_broadcast_sd(double const * __a)78*0a6a1f1dSLionel Sambuc test_mm256_broadcast_sd(double const *__a) {
79*0a6a1f1dSLionel Sambuc // CHECK-LABEL: @test_mm256_broadcast_sd
80*0a6a1f1dSLionel Sambuc // CHECK: insertelement <4 x double> {{.*}}, i32 0
81*0a6a1f1dSLionel Sambuc // CHECK: insertelement <4 x double> {{.*}}, i32 1
82*0a6a1f1dSLionel Sambuc // CHECK: insertelement <4 x double> {{.*}}, i32 2
83*0a6a1f1dSLionel Sambuc // CHECK: insertelement <4 x double> {{.*}}, i32 3
84*0a6a1f1dSLionel Sambuc return _mm256_broadcast_sd(__a);
85*0a6a1f1dSLionel Sambuc }
86*0a6a1f1dSLionel Sambuc
87*0a6a1f1dSLionel Sambuc __m256
test_mm256_broadcast_ss(float const * __a)88*0a6a1f1dSLionel Sambuc test_mm256_broadcast_ss(float const *__a) {
89*0a6a1f1dSLionel Sambuc // CHECK-LABEL: @test_mm256_broadcast_ss
90*0a6a1f1dSLionel Sambuc // CHECK: insertelement <8 x float> {{.*}}, i32 0
91*0a6a1f1dSLionel Sambuc // CHECK: insertelement <8 x float> {{.*}}, i32 1
92*0a6a1f1dSLionel Sambuc // CHECK: insertelement <8 x float> {{.*}}, i32 2
93*0a6a1f1dSLionel Sambuc // CHECK: insertelement <8 x float> {{.*}}, i32 3
94*0a6a1f1dSLionel Sambuc // CHECK: insertelement <8 x float> {{.*}}, i32 4
95*0a6a1f1dSLionel Sambuc // CHECK: insertelement <8 x float> {{.*}}, i32 5
96*0a6a1f1dSLionel Sambuc // CHECK: insertelement <8 x float> {{.*}}, i32 6
97*0a6a1f1dSLionel Sambuc // CHECK: insertelement <8 x float> {{.*}}, i32 7
98*0a6a1f1dSLionel Sambuc return _mm256_broadcast_ss(__a);
99*0a6a1f1dSLionel Sambuc }
100