[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / X86 / sse41-builtins.c
blobd71a4b7e789ef86dbb9d4960e0256ff406f79d4d
1 // RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK,X64
2 // RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK,X64
3 // RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +sse4.1 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK
4 // RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +sse4.1 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK
5 // RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK,X64
6 // RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK,X64
7 // RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +sse4.1 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK
8 // RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +sse4.1 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK
11 #include <immintrin.h>
13 // NOTE: This should match the tests in llvm/test/CodeGen/X86/sse41-intrinsics-fast-isel.ll
15 __m128i test_mm_blend_epi16(__m128i V1, __m128i V2) {
16 // CHECK-LABEL: test_mm_blend_epi16
17 // CHECK: shufflevector <8 x i16> %{{.*}}, <8 x i16> %{{.*}}, <8 x i32> <i32 0, i32 9, i32 2, i32 11, i32 4, i32 13, i32 6, i32 7>
18 return _mm_blend_epi16(V1, V2, 42);
21 __m128d test_mm_blend_pd(__m128d V1, __m128d V2) {
22 // CHECK-LABEL: test_mm_blend_pd
23 // CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x i32> <i32 0, i32 3>
24 return _mm_blend_pd(V1, V2, 2);
27 __m128 test_mm_blend_ps(__m128 V1, __m128 V2) {
28 // CHECK-LABEL: test_mm_blend_ps
29 // CHECK: shufflevector <4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x i32> <i32 0, i32 5, i32 6, i32 3>
30 return _mm_blend_ps(V1, V2, 6);
33 __m128i test_mm_blendv_epi8(__m128i V1, __m128i V2, __m128i V3) {
34 // CHECK-LABEL: test_mm_blendv_epi8
35 // CHECK: call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %{{.*}}, <16 x i8> %{{.*}}, <16 x i8> %{{.*}})
36 return _mm_blendv_epi8(V1, V2, V3);
39 __m128d test_mm_blendv_pd(__m128d V1, __m128d V2, __m128d V3) {
40 // CHECK-LABEL: test_mm_blendv_pd
41 // CHECK: call {{.*}}<2 x double> @llvm.x86.sse41.blendvpd(<2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x double> %{{.*}})
42 return _mm_blendv_pd(V1, V2, V3);
45 __m128 test_mm_blendv_ps(__m128 V1, __m128 V2, __m128 V3) {
46 // CHECK-LABEL: test_mm_blendv_ps
47 // CHECK: call {{.*}}<4 x float> @llvm.x86.sse41.blendvps(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}})
48 return _mm_blendv_ps(V1, V2, V3);
51 __m128d test_mm_ceil_pd(__m128d x) {
52 // CHECK-LABEL: test_mm_ceil_pd
53 // CHECK: call {{.*}}<2 x double> @llvm.x86.sse41.round.pd(<2 x double> %{{.*}}, i32 2)
54 return _mm_ceil_pd(x);
57 __m128 test_mm_ceil_ps(__m128 x) {
58 // CHECK-LABEL: test_mm_ceil_ps
59 // CHECK: call {{.*}}<4 x float> @llvm.x86.sse41.round.ps(<4 x float> %{{.*}}, i32 2)
60 return _mm_ceil_ps(x);
63 __m128d test_mm_ceil_sd(__m128d x, __m128d y) {
64 // CHECK-LABEL: test_mm_ceil_sd
65 // CHECK: call {{.*}}<2 x double> @llvm.x86.sse41.round.sd(<2 x double> %{{.*}}, <2 x double> %{{.*}}, i32 2)
66 return _mm_ceil_sd(x, y);
69 __m128 test_mm_ceil_ss(__m128 x, __m128 y) {
70 // CHECK-LABEL: test_mm_ceil_ss
71 // CHECK: call {{.*}}<4 x float> @llvm.x86.sse41.round.ss(<4 x float> %{{.*}}, <4 x float> %{{.*}}, i32 2)
72 return _mm_ceil_ss(x, y);
75 __m128i test_mm_cmpeq_epi64(__m128i A, __m128i B) {
76 // CHECK-LABEL: test_mm_cmpeq_epi64
77 // CHECK: icmp eq <2 x i64>
78 // CHECK: sext <2 x i1> %{{.*}} to <2 x i64>
79 return _mm_cmpeq_epi64(A, B);
82 __m128i test_mm_cvtepi8_epi16(__m128i a) {
83 // CHECK-LABEL: test_mm_cvtepi8_epi16
84 // CHECK: shufflevector <16 x i8> {{.*}}, <16 x i8> {{.*}}, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
85 // CHECK: sext <8 x i8> {{.*}} to <8 x i16>
86 return _mm_cvtepi8_epi16(a);
89 __m128i test_mm_cvtepi8_epi32(__m128i a) {
90 // CHECK-LABEL: test_mm_cvtepi8_epi32
91 // CHECK: shufflevector <16 x i8> {{.*}}, <16 x i8> {{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
92 // CHECK: sext <4 x i8> {{.*}} to <4 x i32>
93 return _mm_cvtepi8_epi32(a);
96 __m128i test_mm_cvtepi8_epi64(__m128i a) {
97 // CHECK-LABEL: test_mm_cvtepi8_epi64
98 // CHECK: shufflevector <16 x i8> {{.*}}, <16 x i8> {{.*}}, <2 x i32> <i32 0, i32 1>
99 // CHECK: sext <2 x i8> {{.*}} to <2 x i64>
100 return _mm_cvtepi8_epi64(a);
103 __m128i test_mm_cvtepi16_epi32(__m128i a) {
104 // CHECK-LABEL: test_mm_cvtepi16_epi32
105 // CHECK: shufflevector <8 x i16> {{.*}}, <8 x i16> {{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
106 // CHECK: sext <4 x i16> {{.*}} to <4 x i32>
107 return _mm_cvtepi16_epi32(a);
110 __m128i test_mm_cvtepi16_epi64(__m128i a) {
111 // CHECK-LABEL: test_mm_cvtepi16_epi64
112 // CHECK: shufflevector <8 x i16> {{.*}}, <8 x i16> {{.*}}, <2 x i32> <i32 0, i32 1>
113 // CHECK: sext <2 x i16> {{.*}} to <2 x i64>
114 return _mm_cvtepi16_epi64(a);
117 __m128i test_mm_cvtepi32_epi64(__m128i a) {
118 // CHECK-LABEL: test_mm_cvtepi32_epi64
119 // CHECK: shufflevector <4 x i32> {{.*}}, <4 x i32> {{.*}}, <2 x i32> <i32 0, i32 1>
120 // CHECK: sext <2 x i32> {{.*}} to <2 x i64>
121 return _mm_cvtepi32_epi64(a);
124 __m128i test_mm_cvtepu8_epi16(__m128i a) {
125 // CHECK-LABEL: test_mm_cvtepu8_epi16
126 // CHECK: shufflevector <16 x i8> {{.*}}, <16 x i8> {{.*}}, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
127 // CHECK: zext <8 x i8> {{.*}} to <8 x i16>
128 return _mm_cvtepu8_epi16(a);
131 __m128i test_mm_cvtepu8_epi32(__m128i a) {
132 // CHECK-LABEL: test_mm_cvtepu8_epi32
133 // CHECK: shufflevector <16 x i8> {{.*}}, <16 x i8> {{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
134 // CHECK: zext <4 x i8> {{.*}} to <4 x i32>
135 return _mm_cvtepu8_epi32(a);
138 __m128i test_mm_cvtepu8_epi64(__m128i a) {
139 // CHECK-LABEL: test_mm_cvtepu8_epi64
140 // CHECK: shufflevector <16 x i8> {{.*}}, <16 x i8> {{.*}}, <2 x i32> <i32 0, i32 1>
141 // CHECK: zext <2 x i8> {{.*}} to <2 x i64>
142 return _mm_cvtepu8_epi64(a);
145 __m128i test_mm_cvtepu16_epi32(__m128i a) {
146 // CHECK-LABEL: test_mm_cvtepu16_epi32
147 // CHECK: shufflevector <8 x i16> {{.*}}, <8 x i16> {{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
148 // CHECK: zext <4 x i16> {{.*}} to <4 x i32>
149 return _mm_cvtepu16_epi32(a);
152 __m128i test_mm_cvtepu16_epi64(__m128i a) {
153 // CHECK-LABEL: test_mm_cvtepu16_epi64
154 // CHECK: shufflevector <8 x i16> {{.*}}, <8 x i16> {{.*}}, <2 x i32> <i32 0, i32 1>
155 // CHECK: zext <2 x i16> {{.*}} to <2 x i64>
156 return _mm_cvtepu16_epi64(a);
159 __m128i test_mm_cvtepu32_epi64(__m128i a) {
160 // CHECK-LABEL: test_mm_cvtepu32_epi64
161 // CHECK: shufflevector <4 x i32> {{.*}}, <4 x i32> {{.*}}, <2 x i32> <i32 0, i32 1>
162 // CHECK: zext <2 x i32> {{.*}} to <2 x i64>
163 return _mm_cvtepu32_epi64(a);
166 __m128d test_mm_dp_pd(__m128d x, __m128d y) {
167 // CHECK-LABEL: test_mm_dp_pd
168 // CHECK: call {{.*}}<2 x double> @llvm.x86.sse41.dppd(<2 x double> {{.*}}, <2 x double> {{.*}}, i8 7)
169 return _mm_dp_pd(x, y, 7);
172 __m128 test_mm_dp_ps(__m128 x, __m128 y) {
173 // CHECK-LABEL: test_mm_dp_ps
174 // CHECK: call {{.*}}<4 x float> @llvm.x86.sse41.dpps(<4 x float> {{.*}}, <4 x float> {{.*}}, i8 7)
175 return _mm_dp_ps(x, y, 7);
178 int test_mm_extract_epi8(__m128i x) {
179 // CHECK-LABEL: test_mm_extract_epi8
180 // CHECK: extractelement <16 x i8> %{{.*}}, {{i32|i64}} 1
181 // CHECK: zext i8 %{{.*}} to i32
182 return _mm_extract_epi8(x, 1);
185 int test_mm_extract_epi32(__m128i x) {
186 // CHECK-LABEL: test_mm_extract_epi32
187 // CHECK: extractelement <4 x i32> %{{.*}}, {{i32|i64}} 1
188 return _mm_extract_epi32(x, 1);
191 long long test_mm_extract_epi64(__m128i x) {
192 // CHECK-LABEL: test_mm_extract_epi64
193 // CHECK: extractelement <2 x i64> %{{.*}}, {{i32|i64}} 1
194 return _mm_extract_epi64(x, 1);
197 int test_mm_extract_ps(__m128 x) {
198 // CHECK-LABEL: test_mm_extract_ps
199 // CHECK: extractelement <4 x float> %{{.*}}, {{i32|i64}} 1
200 return _mm_extract_ps(x, 1);
203 __m128d test_mm_floor_pd(__m128d x) {
204 // CHECK-LABEL: test_mm_floor_pd
205 // CHECK: call {{.*}}<2 x double> @llvm.x86.sse41.round.pd(<2 x double> %{{.*}}, i32 1)
206 return _mm_floor_pd(x);
209 __m128 test_mm_floor_ps(__m128 x) {
210 // CHECK-LABEL: test_mm_floor_ps
211 // CHECK: call {{.*}}<4 x float> @llvm.x86.sse41.round.ps(<4 x float> %{{.*}}, i32 1)
212 return _mm_floor_ps(x);
215 __m128d test_mm_floor_sd(__m128d x, __m128d y) {
216 // CHECK-LABEL: test_mm_floor_sd
217 // CHECK: call {{.*}}<2 x double> @llvm.x86.sse41.round.sd(<2 x double> %{{.*}}, <2 x double> %{{.*}}, i32 1)
218 return _mm_floor_sd(x, y);
221 __m128 test_mm_floor_ss(__m128 x, __m128 y) {
222 // CHECK-LABEL: test_mm_floor_ss
223 // CHECK: call {{.*}}<4 x float> @llvm.x86.sse41.round.ss(<4 x float> %{{.*}}, <4 x float> %{{.*}}, i32 1)
224 return _mm_floor_ss(x, y);
227 __m128i test_mm_insert_epi8(__m128i x, char b) {
228 // CHECK-LABEL: test_mm_insert_epi8
229 // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, {{i32|i64}} 1
230 return _mm_insert_epi8(x, b, 1);
233 __m128i test_mm_insert_epi32(__m128i x, int b) {
234 // CHECK-LABEL: test_mm_insert_epi32
235 // CHECK: insertelement <4 x i32> %{{.*}}, i32 %{{.*}}, {{i32|i64}} 1
236 return _mm_insert_epi32(x, b, 1);
239 #ifdef __x86_64__
240 __m128i test_mm_insert_epi64(__m128i x, long long b) {
241 // X64-LABEL: test_mm_insert_epi64
242 // X64: insertelement <2 x i64> %{{.*}}, i64 %{{.*}}, {{i32|i64}} 1
243 return _mm_insert_epi64(x, b, 1);
245 #endif
247 __m128 test_mm_insert_ps(__m128 x, __m128 y) {
248 // CHECK-LABEL: test_mm_insert_ps
249 // CHECK: call {{.*}}<4 x float> @llvm.x86.sse41.insertps(<4 x float> %{{.*}}, <4 x float> %{{.*}}, i8 4)
250 return _mm_insert_ps(x, y, 4);
253 __m128i test_mm_max_epi8(__m128i x, __m128i y) {
254 // CHECK-LABEL: test_mm_max_epi8
255 // CHECK: call <16 x i8> @llvm.smax.v16i8(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
256 return _mm_max_epi8(x, y);
259 __m128i test_mm_max_epi32(__m128i x, __m128i y) {
260 // CHECK-LABEL: test_mm_max_epi32
261 // CHECK: call <4 x i32> @llvm.smax.v4i32(<4 x i32> %{{.*}}, <4 x i32> %{{.*}})
262 return _mm_max_epi32(x, y);
265 __m128i test_mm_max_epu16(__m128i x, __m128i y) {
266 // CHECK-LABEL: test_mm_max_epu16
267 // CHECK: call <8 x i16> @llvm.umax.v8i16(<8 x i16> %{{.*}}, <8 x i16> %{{.*}})
268 return _mm_max_epu16(x, y);
271 __m128i test_mm_max_epu32(__m128i x, __m128i y) {
272 // CHECK-LABEL: test_mm_max_epu32
273 // CHECK: call <4 x i32> @llvm.umax.v4i32(<4 x i32> %{{.*}}, <4 x i32> %{{.*}})
274 return _mm_max_epu32(x, y);
277 __m128i test_mm_min_epi8(__m128i x, __m128i y) {
278 // CHECK-LABEL: test_mm_min_epi8
279 // CHECK: call <16 x i8> @llvm.smin.v16i8(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
280 return _mm_min_epi8(x, y);
283 __m128i test_mm_min_epi32(__m128i x, __m128i y) {
284 // CHECK-LABEL: test_mm_min_epi32
285 // CHECK: call <4 x i32> @llvm.smin.v4i32(<4 x i32> %{{.*}}, <4 x i32> %{{.*}})
286 return _mm_min_epi32(x, y);
289 __m128i test_mm_min_epu16(__m128i x, __m128i y) {
290 // CHECK-LABEL: test_mm_min_epu16
291 // CHECK: call <8 x i16> @llvm.umin.v8i16(<8 x i16> %{{.*}}, <8 x i16> %{{.*}})
292 return _mm_min_epu16(x, y);
295 __m128i test_mm_min_epu32(__m128i x, __m128i y) {
296 // CHECK-LABEL: test_mm_min_epu32
297 // CHECK: call <4 x i32> @llvm.umin.v4i32(<4 x i32> %{{.*}}, <4 x i32> %{{.*}})
298 return _mm_min_epu32(x, y);
301 __m128i test_mm_minpos_epu16(__m128i x) {
302 // CHECK-LABEL: test_mm_minpos_epu16
303 // CHECK: call <8 x i16> @llvm.x86.sse41.phminposuw(<8 x i16> %{{.*}})
304 return _mm_minpos_epu16(x);
307 __m128i test_mm_mpsadbw_epu8(__m128i x, __m128i y) {
308 // CHECK-LABEL: test_mm_mpsadbw_epu8
309 // CHECK: call <8 x i16> @llvm.x86.sse41.mpsadbw(<16 x i8> %{{.*}}, <16 x i8> %{{.*}}, i8 1)
310 return _mm_mpsadbw_epu8(x, y, 1);
313 __m128i test_mm_mul_epi32(__m128i x, __m128i y) {
314 // CHECK-LABEL: test_mm_mul_epi32
315 // CHECK: shl <2 x i64> %{{.*}}, splat (i64 32)
316 // CHECK: ashr <2 x i64> %{{.*}}, splat (i64 32)
317 // CHECK: shl <2 x i64> %{{.*}}, splat (i64 32)
318 // CHECK: ashr <2 x i64> %{{.*}}, splat (i64 32)
319 // CHECK: mul <2 x i64> %{{.*}}, %{{.*}}
320 return _mm_mul_epi32(x, y);
323 __m128i test_mm_mullo_epi32(__m128i x, __m128i y) {
324 // CHECK-LABEL: test_mm_mullo_epi32
325 // CHECK: mul <4 x i32>
326 return _mm_mullo_epi32(x, y);
329 __m128i test_mm_packus_epi32(__m128i x, __m128i y) {
330 // CHECK-LABEL: test_mm_packus_epi32
331 // CHECK: call <8 x i16> @llvm.x86.sse41.packusdw(<4 x i32> %{{.*}}, <4 x i32> %{{.*}})
332 return _mm_packus_epi32(x, y);
335 __m128d test_mm_round_pd(__m128d x) {
336 // CHECK-LABEL: test_mm_round_pd
337 // CHECK: call {{.*}}<2 x double> @llvm.x86.sse41.round.pd(<2 x double> %{{.*}}, i32 4)
338 return _mm_round_pd(x, 4);
341 __m128 test_mm_round_ps(__m128 x) {
342 // CHECK-LABEL: test_mm_round_ps
343 // CHECK: call {{.*}}<4 x float> @llvm.x86.sse41.round.ps(<4 x float> %{{.*}}, i32 4)
344 return _mm_round_ps(x, 4);
347 __m128d test_mm_round_sd(__m128d x, __m128d y) {
348 // CHECK-LABEL: test_mm_round_sd
349 // CHECK: call {{.*}}<2 x double> @llvm.x86.sse41.round.sd(<2 x double> %{{.*}}, <2 x double> %{{.*}}, i32 4)
350 return _mm_round_sd(x, y, 4);
353 __m128 test_mm_round_ss(__m128 x, __m128 y) {
354 // CHECK-LABEL: test_mm_round_ss
355 // CHECK: call {{.*}}<4 x float> @llvm.x86.sse41.round.ss(<4 x float> %{{.*}}, <4 x float> %{{.*}}, i32 4)
356 return _mm_round_ss(x, y, 4);
359 __m128i test_mm_stream_load_si128(__m128i const *a) {
360 // CHECK-LABEL: test_mm_stream_load_si128
361 // CHECK: load <2 x i64>, ptr %{{.*}}, align 16, !nontemporal
362 return _mm_stream_load_si128(a);
365 __m128i test_mm_stream_load_si128_void(const void *a) {
366 // CHECK-LABEL: test_mm_stream_load_si128_void
367 // CHECK: load <2 x i64>, ptr %{{.*}}, align 16, !nontemporal
368 return _mm_stream_load_si128(a);
371 int test_mm_test_all_ones(__m128i x) {
372 // CHECK-LABEL: test_mm_test_all_ones
373 // CHECK: call {{.*}}i32 @llvm.x86.sse41.ptestc(<2 x i64> %{{.*}}, <2 x i64> %{{.*}})
374 return _mm_test_all_ones(x);
377 int test_mm_test_all_zeros(__m128i x, __m128i y) {
378 // CHECK-LABEL: test_mm_test_all_zeros
379 // CHECK: call {{.*}}i32 @llvm.x86.sse41.ptestz(<2 x i64> %{{.*}}, <2 x i64> %{{.*}})
380 return _mm_test_all_zeros(x, y);
383 int test_mm_test_mix_ones_zeros(__m128i x, __m128i y) {
384 // CHECK-LABEL: test_mm_test_mix_ones_zeros
385 // CHECK: call {{.*}}i32 @llvm.x86.sse41.ptestnzc(<2 x i64> %{{.*}}, <2 x i64> %{{.*}})
386 return _mm_test_mix_ones_zeros(x, y);
389 int test_mm_testc_si128(__m128i x, __m128i y) {
390 // CHECK-LABEL: test_mm_testc_si128
391 // CHECK: call {{.*}}i32 @llvm.x86.sse41.ptestc(<2 x i64> %{{.*}}, <2 x i64> %{{.*}})
392 return _mm_testc_si128(x, y);
395 int test_mm_testnzc_si128(__m128i x, __m128i y) {
396 // CHECK-LABEL: test_mm_testnzc_si128
397 // CHECK: call {{.*}}i32 @llvm.x86.sse41.ptestnzc(<2 x i64> %{{.*}}, <2 x i64> %{{.*}})
398 return _mm_testnzc_si128(x, y);
401 int test_mm_testz_si128(__m128i x, __m128i y) {
402 // CHECK-LABEL: test_mm_testz_si128
403 // CHECK: call {{.*}}i32 @llvm.x86.sse41.ptestz(<2 x i64> %{{.*}}, <2 x i64> %{{.*}})
404 return _mm_testz_si128(x, y);