xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/cvt16.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -march=x86-64 -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -mattr=-f16c | FileCheck %s -check-prefix=CHECK -check-prefix=LIBCALL
2*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -march=x86-64 -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -mattr=+f16c | FileCheck %s -check-prefix=CHECK -check-prefix=F16C
3*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -march=x86-64 -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -mattr=-f16c,+soft-float | FileCheck %s -check-prefix=CHECK -check-prefix=SOFTFLOAT
4*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -march=x86-64 -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -mattr=+f16c,+soft-float | FileCheck %s -check-prefix=CHECK -check-prefix=SOFTFLOAT
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Worker; This is a test for float to half float conversions on x86-64.
7*9880d681SAndroid Build Coastguard Worker;
8*9880d681SAndroid Build Coastguard Worker; If flag -soft-float is set, or if there is no F16C support, then:
9*9880d681SAndroid Build Coastguard Worker; 1) half float to float conversions are
10*9880d681SAndroid Build Coastguard Worker;    translated into calls to __gnu_h2f_ieee defined
11*9880d681SAndroid Build Coastguard Worker;    by the compiler runtime library;
12*9880d681SAndroid Build Coastguard Worker; 2) float to half float conversions are translated into calls
13*9880d681SAndroid Build Coastguard Worker;    to __gnu_f2h_ieee which expected to be defined by the
14*9880d681SAndroid Build Coastguard Worker;    compiler runtime library.
15*9880d681SAndroid Build Coastguard Worker;
16*9880d681SAndroid Build Coastguard Worker; Otherwise (we have F16C support):
17*9880d681SAndroid Build Coastguard Worker; 1) half float to float conversion are translated using
18*9880d681SAndroid Build Coastguard Worker;    vcvtph2ps instructions;
19*9880d681SAndroid Build Coastguard Worker; 2) float to half float conversions are translated using
20*9880d681SAndroid Build Coastguard Worker;    vcvtps2ph instructions
21*9880d681SAndroid Build Coastguard Worker
22*9880d681SAndroid Build Coastguard Worker
23*9880d681SAndroid Build Coastguard Workerdefine void @test1(float %src, i16* %dest) {
24*9880d681SAndroid Build Coastguard Worker  %1 = tail call i16 @llvm.convert.to.fp16.f32(float %src)
25*9880d681SAndroid Build Coastguard Worker  store i16 %1, i16* %dest, align 2
26*9880d681SAndroid Build Coastguard Worker  ret void
27*9880d681SAndroid Build Coastguard Worker}
28*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test1
29*9880d681SAndroid Build Coastguard Worker; LIBCALL: callq  __gnu_f2h_ieee
30*9880d681SAndroid Build Coastguard Worker; SOFTFLOAT: callq  __gnu_f2h_ieee
31*9880d681SAndroid Build Coastguard Worker; F16C: vcvtps2ph
32*9880d681SAndroid Build Coastguard Worker; CHECK: ret
33*9880d681SAndroid Build Coastguard Worker
34*9880d681SAndroid Build Coastguard Worker
35*9880d681SAndroid Build Coastguard Workerdefine float @test2(i16* nocapture %src) {
36*9880d681SAndroid Build Coastguard Worker  %1 = load i16, i16* %src, align 2
37*9880d681SAndroid Build Coastguard Worker  %2 = tail call float @llvm.convert.from.fp16.f32(i16 %1)
38*9880d681SAndroid Build Coastguard Worker  ret float %2
39*9880d681SAndroid Build Coastguard Worker}
40*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test2:
41*9880d681SAndroid Build Coastguard Worker; LIBCALL: jmp  __gnu_h2f_ieee
42*9880d681SAndroid Build Coastguard Worker; SOFTFLOAT: callq  __gnu_h2f_ieee
43*9880d681SAndroid Build Coastguard Worker; F16C: vcvtph2ps
44*9880d681SAndroid Build Coastguard Worker; F16C: ret
45*9880d681SAndroid Build Coastguard Worker
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Workerdefine float @test3(float %src) nounwind uwtable readnone {
48*9880d681SAndroid Build Coastguard Worker  %1 = tail call i16 @llvm.convert.to.fp16.f32(float %src)
49*9880d681SAndroid Build Coastguard Worker  %2 = tail call float @llvm.convert.from.fp16.f32(i16 %1)
50*9880d681SAndroid Build Coastguard Worker  ret float %2
51*9880d681SAndroid Build Coastguard Worker}
52*9880d681SAndroid Build Coastguard Worker
53*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test3:
54*9880d681SAndroid Build Coastguard Worker; LIBCALL: callq  __gnu_f2h_ieee
55*9880d681SAndroid Build Coastguard Worker; LIBCALL: jmp   __gnu_h2f_ieee
56*9880d681SAndroid Build Coastguard Worker; SOFTFLOAT: callq  __gnu_f2h_ieee
57*9880d681SAndroid Build Coastguard Worker; SOFTFLOAT: callq  __gnu_h2f_ieee
58*9880d681SAndroid Build Coastguard Worker; F16C: vcvtps2ph
59*9880d681SAndroid Build Coastguard Worker; F16C-NEXT: vcvtph2ps
60*9880d681SAndroid Build Coastguard Worker; F16C: ret
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard Workerdefine double @test4(i16* nocapture %src) {
63*9880d681SAndroid Build Coastguard Worker  %1 = load i16, i16* %src, align 2
64*9880d681SAndroid Build Coastguard Worker  %2 = tail call double @llvm.convert.from.fp16.f64(i16 %1)
65*9880d681SAndroid Build Coastguard Worker  ret double %2
66*9880d681SAndroid Build Coastguard Worker}
67*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test4:
68*9880d681SAndroid Build Coastguard Worker; LIBCALL: callq  __gnu_h2f_ieee
69*9880d681SAndroid Build Coastguard Worker; LIBCALL: cvtss2sd
70*9880d681SAndroid Build Coastguard Worker; SOFTFLOAT: callq  __gnu_h2f_ieee
71*9880d681SAndroid Build Coastguard Worker; SOFTFLOAT: callq __extendsfdf2
72*9880d681SAndroid Build Coastguard Worker; F16C: vcvtph2ps
73*9880d681SAndroid Build Coastguard Worker; F16C: vcvtss2sd
74*9880d681SAndroid Build Coastguard Worker; F16C: ret
75*9880d681SAndroid Build Coastguard Worker
76*9880d681SAndroid Build Coastguard Worker
77*9880d681SAndroid Build Coastguard Workerdefine i16 @test5(double %src) {
78*9880d681SAndroid Build Coastguard Worker  %val = tail call i16 @llvm.convert.to.fp16.f64(double %src)
79*9880d681SAndroid Build Coastguard Worker  ret i16 %val
80*9880d681SAndroid Build Coastguard Worker}
81*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test5:
82*9880d681SAndroid Build Coastguard Worker; LIBCALL: jmp  __truncdfhf2
83*9880d681SAndroid Build Coastguard Worker; SOFTFLOAT: callq  __truncdfhf2
84*9880d681SAndroid Build Coastguard Worker; F16C: jmp __truncdfhf2
85*9880d681SAndroid Build Coastguard Worker
86*9880d681SAndroid Build Coastguard Workerdeclare float @llvm.convert.from.fp16.f32(i16) nounwind readnone
87*9880d681SAndroid Build Coastguard Workerdeclare i16 @llvm.convert.to.fp16.f32(float) nounwind readnone
88*9880d681SAndroid Build Coastguard Workerdeclare double @llvm.convert.from.fp16.f64(i16) nounwind readnone
89*9880d681SAndroid Build Coastguard Workerdeclare i16 @llvm.convert.to.fp16.f64(double) nounwind readnone
90