1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instcombine -S | FileCheck %s
3
4declare <4 x float> @llvm.x86.vcvtph2ps.128(<8 x i16>)
5declare <8 x float> @llvm.x86.vcvtph2ps.256(<8 x i16>)
6
7;
8; Vector Demanded Elts
9;
10
11; Only bottom 4 elements required.
12define <4 x float> @demand_vcvtph2ps_128(<8 x i16> %A) {
13; CHECK-LABEL: @demand_vcvtph2ps_128(
14; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <8 x i16> [[A:%.*]], <8 x i16> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
15; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <4 x i16> [[TMP1]] to <4 x half>
16; CHECK-NEXT:    [[CVTPH2PS:%.*]] = fpext <4 x half> [[TMP2]] to <4 x float>
17; CHECK-NEXT:    ret <4 x float> [[CVTPH2PS]]
18;
19  %1 = shufflevector <8 x i16> %A, <8 x i16> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3>
20  %2 = tail call <4 x float> @llvm.x86.vcvtph2ps.128(<8 x i16> %1)
21  ret <4 x float> %2
22}
23
24; All 8 elements required.
25define <8 x float> @demand_vcvtph2ps_256(<8 x i16> %A) {
26; CHECK-LABEL: @demand_vcvtph2ps_256(
27; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <8 x i16> [[A:%.*]], <8 x i16> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3>
28; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <8 x i16> [[TMP1]] to <8 x half>
29; CHECK-NEXT:    [[CVTPH2PS:%.*]] = fpext <8 x half> [[TMP2]] to <8 x float>
30; CHECK-NEXT:    ret <8 x float> [[CVTPH2PS]]
31;
32  %1 = shufflevector <8 x i16> %A, <8 x i16> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3>
33  %2 = tail call <8 x float> @llvm.x86.vcvtph2ps.256(<8 x i16> %1)
34  ret <8 x float> %2
35}
36
37;
38; Constant Folding
39;
40
41define <4 x float> @fold_vcvtph2ps_128() {
42; CHECK-LABEL: @fold_vcvtph2ps_128(
43; CHECK-NEXT:    ret <4 x float> <float 0.000000e+00, float 5.000000e-01, float 1.000000e+00, float -0.000000e+00>
44;
45  %1 = tail call <4 x float> @llvm.x86.vcvtph2ps.128(<8 x i16> <i16 0, i16 14336, i16 15360, i16 32768, i16 16384, i16 31743, i16 48128, i16 49152>)
46  ret <4 x float> %1
47}
48
49define <8 x float> @fold_vcvtph2ps_256() {
50; CHECK-LABEL: @fold_vcvtph2ps_256(
51; CHECK-NEXT:    ret <8 x float> <float 0.000000e+00, float 5.000000e-01, float 1.000000e+00, float -0.000000e+00, float 2.000000e+00, float 6.550400e+04, float -1.000000e+00, float -2.000000e+00>
52;
53  %1 = tail call <8 x float> @llvm.x86.vcvtph2ps.256(<8 x i16> <i16 0, i16 14336, i16 15360, i16 32768, i16 16384, i16 31743, i16 48128, i16 49152>)
54  ret <8 x float> %1
55}
56
57define <4 x float> @fold_vcvtph2ps_128_zero() {
58; CHECK-LABEL: @fold_vcvtph2ps_128_zero(
59; CHECK-NEXT:    ret <4 x float> zeroinitializer
60;
61  %1 = tail call <4 x float> @llvm.x86.vcvtph2ps.128(<8 x i16> <i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>)
62  ret <4 x float> %1
63}
64
65define <8 x float> @fold_vcvtph2ps_256_zero() {
66; CHECK-LABEL: @fold_vcvtph2ps_256_zero(
67; CHECK-NEXT:    ret <8 x float> zeroinitializer
68;
69  %1 = tail call <8 x float> @llvm.x86.vcvtph2ps.256(<8 x i16> <i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>)
70  ret <8 x float> %1
71}
72