| 1 |
// REQUIRES: x86-registered-target |
| 2 |
// RUN: %clang_cc1 -ffreestanding %s -O3 -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,X64 |
| 3 |
// RUN: %clang_cc1 -ffreestanding %s -O3 -triple=i386-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,X86 |
| 4 |
// FIXME: This is testing optimized generation of shuffle instructions and should be fixed. |
| 5 |
|
| 6 |
|
| 7 |
#include <immintrin.h> |
| 8 |
|
| 9 |
// |
| 10 |
// Test LLVM IR codegen of shuffle instructions, checking if the masks are correct |
| 11 |
// |
| 12 |
|
| 13 |
__m256 x(__m256 a, __m256 b) { |
| 14 |
// CHECK-LABEL: x |
| 15 |
// CHECK: shufflevector{{.*}}<i32 3, i32 2, i32 8, i32 11, i32 7, i32 6, i32 12, i32 15> |
| 16 |
return _mm256_shuffle_ps(a, b, 203); |
| 17 |
} |
| 18 |
|
| 19 |
__m128d test_mm_permute_pd(__m128d a) { |
| 20 |
// CHECK-LABEL: test_mm_permute_pd |
| 21 |
// CHECK: shufflevector{{.*}}<i32 1, i32 0> |
| 22 |
return _mm_permute_pd(a, 1); |
| 23 |
} |
| 24 |
|
| 25 |
__m256d test_mm256_permute_pd(__m256d a) { |
| 26 |
// CHECK-LABEL: test_mm256_permute_pd |
| 27 |
// CHECK: shufflevector{{.*}}<i32 1, i32 0, i32 3, i32 2> |
| 28 |
return _mm256_permute_pd(a, 5); |
| 29 |
} |
| 30 |
|
| 31 |
__m128 test_mm_permute_ps(__m128 a) { |
| 32 |
// CHECK-LABEL: test_mm_permute_ps |
| 33 |
// CHECK: shufflevector{{.*}}<i32 3, i32 2, i32 1, i32 0> |
| 34 |
return _mm_permute_ps(a, 0x1b); |
| 35 |
} |
| 36 |
|
| 37 |
// Test case for PR12401 |
| 38 |
__m128 test_mm_permute_ps2(__m128 a) { |
| 39 |
// CHECK-LABEL: test_mm_permute_ps2 |
| 40 |
// CHECK: shufflevector{{.*}}<i32 2, i32 1, i32 2, i32 3> |
| 41 |
return _mm_permute_ps(a, 0xe6); |
| 42 |
} |
| 43 |
|
| 44 |
__m256 test_mm256_permute_ps(__m256 a) { |
| 45 |
// CHECK-LABEL: test_mm256_permute_ps |
| 46 |
// CHECK: shufflevector{{.*}}<i32 3, i32 2, i32 1, i32 0, i32 7, i32 6, i32 5, i32 4> |
| 47 |
return _mm256_permute_ps(a, 0x1b); |
| 48 |
} |
| 49 |
|
| 50 |
__m256d test_mm256_permute2f128_pd(__m256d a, __m256d b) { |
| 51 |
// CHECK-LABEL: test_mm256_permute2f128_pd |
| 52 |
// CHECK: shufflevector{{.*}}<i32 2, i32 3, i32 6, i32 7> |
| 53 |
return _mm256_permute2f128_pd(a, b, 0x31); |
| 54 |
} |
| 55 |
|
| 56 |
__m256 test_mm256_permute2f128_ps(__m256 a, __m256 b) { |
| 57 |
// CHECK-LABEL: test_mm256_permute2f128_ps |
| 58 |
// CHECK: shufflevector{{.*}}<i32 4, i32 5, i32 6, i32 7, i32 12, i32 13, i32 14, i32 15> |
| 59 |
return _mm256_permute2f128_ps(a, b, 0x13); |
| 60 |
} |
| 61 |
|
| 62 |
__m256i test_mm256_permute2f128_si256(__m256i a, __m256i b) { |
| 63 |
// CHECK-LABEL: test_mm256_permute2f128_si256 |
| 64 |
// CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 4, i32 5> |
| 65 |
return _mm256_permute2f128_si256(a, b, 0x20); |
| 66 |
} |
| 67 |
|
| 68 |
__m128 |
| 69 |
test_mm_broadcast_ss(float const *__a) { |
| 70 |
// CHECK-LABEL: test_mm_broadcast_ss |
| 71 |
// CHECK: insertelement <4 x float> {{.*}}, i64 0 |
| 72 |
// CHECK: shufflevector <4 x float> {{.*}}, <4 x float> poison, <4 x i32> zeroinitializer |
| 73 |
return _mm_broadcast_ss(__a); |
| 74 |
} |
| 75 |
|
| 76 |
__m256d |
| 77 |
test_mm256_broadcast_sd(double const *__a) { |
| 78 |
// CHECK-LABEL: test_mm256_broadcast_sd |
| 79 |
// CHECK: insertelement <4 x double> {{.*}}, i64 0 |
| 80 |
// CHECK: shufflevector <4 x double> {{.*}}, <4 x double> poison, <4 x i32> zeroinitializer |
| 81 |
return _mm256_broadcast_sd(__a); |
| 82 |
} |
| 83 |
|
| 84 |
__m256 |
| 85 |
test_mm256_broadcast_ss(float const *__a) { |
| 86 |
// CHECK-LABEL: test_mm256_broadcast_ss |
| 87 |
// CHECK: insertelement <8 x float> {{.*}}, i64 0 |
| 88 |
// CHECK: shufflevector <8 x float> {{.*}}, <8 x float> poison, <8 x i32> zeroinitializer |
| 89 |
return _mm256_broadcast_ss(__a); |
| 90 |
} |
| 91 |
|
| 92 |
// Make sure we have the correct mask for each insertf128 case. |
| 93 |
|
| 94 |
__m256 test_mm256_insertf128_ps_0(__m256 a, __m128 b) { |
| 95 |
// CHECK-LABEL: test_mm256_insertf128_ps_0 |
| 96 |
// CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3, i32 12, i32 13, i32 14, i32 15> |
| 97 |
return _mm256_insertf128_ps(a, b, 0); |
| 98 |
} |
| 99 |
|
| 100 |
__m256d test_mm256_insertf128_pd_0(__m256d a, __m128d b) { |
| 101 |
// CHECK-LABEL: test_mm256_insertf128_pd_0 |
| 102 |
// CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 6, i32 7> |
| 103 |
return _mm256_insertf128_pd(a, b, 0); |
| 104 |
} |
| 105 |
|
| 106 |
__m256i test_mm256_insertf128_si256_0(__m256i a, __m128i b) { |
| 107 |
// CHECK-LABEL: test_mm256_insertf128_si256_0 |
| 108 |
// X64: shufflevector{{.*}}<i32 0, i32 1, i32 6, i32 7> |
| 109 |
// X86: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3, i32 12, i32 13, i32 14, i32 15> |
| 110 |
return _mm256_insertf128_si256(a, b, 0); |
| 111 |
} |
| 112 |
|
| 113 |
__m256 test_mm256_insertf128_ps_1(__m256 a, __m128 b) { |
| 114 |
// CHECK-LABEL: test_mm256_insertf128_ps_1 |
| 115 |
// CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11> |
| 116 |
return _mm256_insertf128_ps(a, b, 1); |
| 117 |
} |
| 118 |
|
| 119 |
__m256d test_mm256_insertf128_pd_1(__m256d a, __m128d b) { |
| 120 |
// CHECK-LABEL: test_mm256_insertf128_pd_1 |
| 121 |
// CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 4, i32 5> |
| 122 |
return _mm256_insertf128_pd(a, b, 1); |
| 123 |
} |
| 124 |
|
| 125 |
__m256i test_mm256_insertf128_si256_1(__m256i a, __m128i b) { |
| 126 |
// CHECK-LABEL: test_mm256_insertf128_si256_1 |
| 127 |
// X64: shufflevector{{.*}}<i32 0, i32 1, i32 4, i32 5> |
| 128 |
// X86: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11> |
| 129 |
return _mm256_insertf128_si256(a, b, 1); |
| 130 |
} |
| 131 |
|
| 132 |
// Make sure we have the correct mask for each extractf128 case. |
| 133 |
|
| 134 |
__m128 test_mm256_extractf128_ps_0(__m256 a) { |
| 135 |
// X64-LABEL: test_mm256_extractf128_ps_0 |
| 136 |
// X64: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3> |
| 137 |
// |
| 138 |
// X86-LABEL: test_mm256_extractf128_ps_0 |
| 139 |
// X86: shufflevector{{.*}}<i32 0, i32 1> |
| 140 |
return _mm256_extractf128_ps(a, 0); |
| 141 |
} |
| 142 |
|
| 143 |
__m128d test_mm256_extractf128_pd_0(__m256d a) { |
| 144 |
// CHECK-LABEL: test_mm256_extractf128_pd_0 |
| 145 |
// CHECK: shufflevector{{.*}}<i32 0, i32 1> |
| 146 |
return _mm256_extractf128_pd(a, 0); |
| 147 |
} |
| 148 |
|
| 149 |
__m128i test_mm256_extractf128_si256_0(__m256i a) { |
| 150 |
// CHECK-LABEL: test_mm256_extractf128_si256_0 |
| 151 |
// CHECK: shufflevector{{.*}}<i32 0, i32 1> |
| 152 |
return _mm256_extractf128_si256(a, 0); |
| 153 |
} |
| 154 |
|
| 155 |
__m128 test_mm256_extractf128_ps_1(__m256 a) { |
| 156 |
// X64-LABEL: test_mm256_extractf128_ps_1 |
| 157 |
// X64: shufflevector{{.*}}<i32 4, i32 5, i32 6, i32 7> |
| 158 |
// |
| 159 |
// X86-LABEL: test_mm256_extractf128_ps_1 |
| 160 |
// X86: shufflevector{{.*}}<i32 2, i32 3> |
| 161 |
return _mm256_extractf128_ps(a, 1); |
| 162 |
} |
| 163 |
|
| 164 |
__m128d test_mm256_extractf128_pd_1(__m256d a) { |
| 165 |
// CHECK-LABEL: test_mm256_extractf128_pd_1 |
| 166 |
// CHECK: shufflevector{{.*}}<i32 2, i32 3> |
| 167 |
return _mm256_extractf128_pd(a, 1); |
| 168 |
} |
| 169 |
|
| 170 |
__m128i test_mm256_extractf128_si256_1(__m256i a) { |
| 171 |
// CHECK-LABEL: test_mm256_extractf128_si256_1 |
| 172 |
// CHECK: shufflevector{{.*}}<i32 2, i32 3> |
| 173 |
return _mm256_extractf128_si256(a, 1); |
| 174 |
} |
| 175 |
|
| 176 |
__m256 test_mm256_set_m128(__m128 hi, __m128 lo) { |
| 177 |
// CHECK-LABEL: test_mm256_set_m128 |
| 178 |
// CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7> |
| 179 |
return _mm256_set_m128(hi, lo); |
| 180 |
} |
| 181 |
|
| 182 |
__m256d test_mm256_set_m128d(__m128d hi, __m128d lo) { |
| 183 |
// CHECK-LABEL: test_mm256_set_m128d |
| 184 |
// CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3> |
| 185 |
return _mm256_set_m128d(hi, lo); |
| 186 |
} |
| 187 |
|
| 188 |
__m256i test_mm256_set_m128i(__m128i hi, __m128i lo) { |
| 189 |
// CHECK-LABEL: test_mm256_set_m128i |
| 190 |
// CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3> |
| 191 |
return _mm256_set_m128i(hi, lo); |
| 192 |
} |
| 193 |
|
| 194 |
__m256 test_mm256_setr_m128(__m128 hi, __m128 lo) { |
| 195 |
// CHECK-LABEL: test_mm256_setr_m128 |
| 196 |
// CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7> |
| 197 |
return _mm256_setr_m128(lo, hi); |
| 198 |
} |
| 199 |
|
| 200 |
__m256d test_mm256_setr_m128d(__m128d hi, __m128d lo) { |
| 201 |
// CHECK-LABEL: test_mm256_setr_m128d |
| 202 |
// CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3> |
| 203 |
return _mm256_setr_m128d(lo, hi); |
| 204 |
} |
| 205 |
|
| 206 |
__m256i test_mm256_setr_m128i(__m128i hi, __m128i lo) { |
| 207 |
// CHECK-LABEL: test_mm256_setr_m128i |
| 208 |
// CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3> |
| 209 |
return _mm256_setr_m128i(lo, hi); |
| 210 |
} |