1 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +f16c -emit-llvm -o - -Wall -Werror | FileCheck %s
2 
3 
4 #include <immintrin.h>
5 
test_cvtsh_ss(unsigned short a)6 float test_cvtsh_ss(unsigned short a) {
7   // CHECK-LABEL: test_cvtsh_ss
8   // CHECK: insertelement <8 x i16> undef, i16 %{{.*}}, i32 0
9   // CHECK: insertelement <8 x i16> %{{.*}}, i16 0, i32 1
10   // CHECK: insertelement <8 x i16> %{{.*}}, i16 0, i32 2
11   // CHECK: insertelement <8 x i16> %{{.*}}, i16 0, i32 3
12   // CHECK: insertelement <8 x i16> %{{.*}}, i16 0, i32 4
13   // CHECK: insertelement <8 x i16> %{{.*}}, i16 0, i32 5
14   // CHECK: insertelement <8 x i16> %{{.*}}, i16 0, i32 6
15   // CHECK: insertelement <8 x i16> %{{.*}}, i16 0, i32 7
16   // CHECK: shufflevector <8 x i16> %{{.*}}, <8 x i16> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
17   // CHECK: bitcast <4 x i16> %{{.*}} to <4 x half>
18   // CHECK: fpext <4 x half> %{{.*}} to <4 x float>
19   // CHECK: extractelement <4 x float> %{{.*}}, i32 0
20   return _cvtsh_ss(a);
21 }
22 
test_cvtss_sh(float a)23 unsigned short test_cvtss_sh(float a) {
24   // CHECK-LABEL: test_cvtss_sh
25   // CHECK: insertelement <4 x float> undef, float %{{.*}}, i32 0
26   // CHECK: insertelement <4 x float> %{{.*}}, float 0.000000e+00, i32 1
27   // CHECK: insertelement <4 x float> %{{.*}}, float 0.000000e+00, i32 2
28   // CHECK: insertelement <4 x float> %{{.*}}, float 0.000000e+00, i32 3
29   // CHECK: call <8 x i16> @llvm.x86.vcvtps2ph.128(<4 x float> %{{.*}}, i32 0)
30   // CHECK: extractelement <8 x i16> %{{.*}}, i32 0
31   return _cvtss_sh(a, 0);
32 }
33 
test_mm_cvtph_ps(__m128i a)34 __m128 test_mm_cvtph_ps(__m128i a) {
35   // CHECK-LABEL: test_mm_cvtph_ps
36   // CHECK: bitcast <2 x i64> %{{.*}} to <8 x i16>
37   // CHECK: shufflevector <8 x i16> %{{.*}}, <8 x i16> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
38   // CHECK: bitcast <4 x i16> %{{.*}} to <4 x half>
39   // CHECK: fpext <4 x half> %{{.*}} to <4 x float>
40   return _mm_cvtph_ps(a);
41 }
42 
test_mm256_cvtph_ps(__m128i a)43 __m256 test_mm256_cvtph_ps(__m128i a) {
44   // CHECK-LABEL: test_mm256_cvtph_ps
45   // CHECK: bitcast <2 x i64> %{{.*}} to <8 x i16>
46   // CHECK: bitcast <8 x i16> %{{.*}} to <8 x half>
47   // CHECK: fpext <8 x half> %{{.*}} to <8 x float>
48   return _mm256_cvtph_ps(a);
49 }
50 
test_mm_cvtps_ph(__m128 a)51 __m128i test_mm_cvtps_ph(__m128 a) {
52   // CHECK-LABEL: test_mm_cvtps_ph
53   // CHECK: call <8 x i16> @llvm.x86.vcvtps2ph.128(<4 x float> %{{.*}}, i32 0)
54   return _mm_cvtps_ph(a, 0);
55 }
56 
test_mm256_cvtps_ph(__m256 a)57 __m128i test_mm256_cvtps_ph(__m256 a) {
58   // CHECK-LABEL: test_mm256_cvtps_ph
59   // CHECK: call <8 x i16> @llvm.x86.vcvtps2ph.256(<8 x float> %{{.*}}, i32 0)
60   return _mm256_cvtps_ph(a, 0);
61 }
62