1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -mattr=-f16c | FileCheck %s -check-prefix=LIBCALL
3 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -mattr=+f16c | FileCheck %s -check-prefix=F16C
4 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -mattr=-f16c,+soft-float | FileCheck %s -check-prefix=SOFTFLOAT
5 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -mattr=+f16c,+soft-float | FileCheck %s -check-prefix=SOFTFLOAT
7 ; This is a test for float to half float conversions on x86-64.
9 ; If flag -soft-float is set, or if there is no F16C support, then:
10 ; 1) half float to float conversions are
11 ; translated into calls to __gnu_h2f_ieee defined
12 ; by the compiler runtime library;
13 ; 2) float to half float conversions are translated into calls
14 ; to __gnu_f2h_ieee which expected to be defined by the
15 ; compiler runtime library.
17 ; Otherwise (we have F16C support):
18 ; 1) half float to float conversion are translated using
19 ; vcvtph2ps instructions;
20 ; 2) float to half float conversions are translated using
21 ; vcvtps2ph instructions
24 define void @test1(float %src, ptr %dest) nounwind {
25 ; LIBCALL-LABEL: test1:
27 ; LIBCALL-NEXT: pushq %rbx
28 ; LIBCALL-NEXT: movq %rdi, %rbx
29 ; LIBCALL-NEXT: callq __truncsfhf2@PLT
30 ; LIBCALL-NEXT: pextrw $0, %xmm0, (%rbx)
31 ; LIBCALL-NEXT: popq %rbx
36 ; F16C-NEXT: vcvtps2ph $4, %xmm0, %xmm0
37 ; F16C-NEXT: vmovd %xmm0, %eax
38 ; F16C-NEXT: movw %ax, (%rdi)
41 ; SOFTFLOAT-LABEL: test1:
43 ; SOFTFLOAT-NEXT: pushq %rbx
44 ; SOFTFLOAT-NEXT: movq %rsi, %rbx
45 ; SOFTFLOAT-NEXT: callq __gnu_f2h_ieee@PLT
46 ; SOFTFLOAT-NEXT: movw %ax, (%rbx)
47 ; SOFTFLOAT-NEXT: popq %rbx
48 ; SOFTFLOAT-NEXT: retq
49 %1 = tail call i16 @llvm.convert.to.fp16.f32(float %src)
50 store i16 %1, ptr %dest, align 2
54 define float @test2(ptr nocapture %src) nounwind {
55 ; LIBCALL-LABEL: test2:
57 ; LIBCALL-NEXT: pinsrw $0, (%rdi), %xmm0
58 ; LIBCALL-NEXT: jmp __extendhfsf2@PLT # TAILCALL
62 ; F16C-NEXT: movzwl (%rdi), %eax
63 ; F16C-NEXT: vmovd %eax, %xmm0
64 ; F16C-NEXT: vcvtph2ps %xmm0, %xmm0
67 ; SOFTFLOAT-LABEL: test2:
69 ; SOFTFLOAT-NEXT: pushq %rax
70 ; SOFTFLOAT-NEXT: movzwl (%rdi), %edi
71 ; SOFTFLOAT-NEXT: callq __gnu_h2f_ieee@PLT
72 ; SOFTFLOAT-NEXT: popq %rcx
73 ; SOFTFLOAT-NEXT: retq
74 %1 = load i16, ptr %src, align 2
75 %2 = tail call float @llvm.convert.from.fp16.f32(i16 %1)
79 define float @test3(float %src) nounwind uwtable readnone {
80 ; LIBCALL-LABEL: test3:
82 ; LIBCALL-NEXT: pushq %rax
83 ; LIBCALL-NEXT: .cfi_def_cfa_offset 16
84 ; LIBCALL-NEXT: callq __truncsfhf2@PLT
85 ; LIBCALL-NEXT: popq %rax
86 ; LIBCALL-NEXT: .cfi_def_cfa_offset 8
87 ; LIBCALL-NEXT: jmp __extendhfsf2@PLT # TAILCALL
91 ; F16C-NEXT: vcvtps2ph $4, %xmm0, %xmm0
92 ; F16C-NEXT: vcvtph2ps %xmm0, %xmm0
95 ; SOFTFLOAT-LABEL: test3:
97 ; SOFTFLOAT-NEXT: pushq %rax
98 ; SOFTFLOAT-NEXT: .cfi_def_cfa_offset 16
99 ; SOFTFLOAT-NEXT: callq __gnu_f2h_ieee@PLT
100 ; SOFTFLOAT-NEXT: movzwl %ax, %edi
101 ; SOFTFLOAT-NEXT: callq __gnu_h2f_ieee@PLT
102 ; SOFTFLOAT-NEXT: popq %rcx
103 ; SOFTFLOAT-NEXT: .cfi_def_cfa_offset 8
104 ; SOFTFLOAT-NEXT: retq
105 %1 = tail call i16 @llvm.convert.to.fp16.f32(float %src)
106 %2 = tail call float @llvm.convert.from.fp16.f32(i16 %1)
110 define double @test4(ptr nocapture %src) nounwind {
111 ; LIBCALL-LABEL: test4:
113 ; LIBCALL-NEXT: pushq %rax
114 ; LIBCALL-NEXT: pinsrw $0, (%rdi), %xmm0
115 ; LIBCALL-NEXT: callq __extendhfsf2@PLT
116 ; LIBCALL-NEXT: cvtss2sd %xmm0, %xmm0
117 ; LIBCALL-NEXT: popq %rax
122 ; F16C-NEXT: movzwl (%rdi), %eax
123 ; F16C-NEXT: vmovd %eax, %xmm0
124 ; F16C-NEXT: vcvtph2ps %xmm0, %xmm0
125 ; F16C-NEXT: vcvtss2sd %xmm0, %xmm0, %xmm0
128 ; SOFTFLOAT-LABEL: test4:
129 ; SOFTFLOAT: # %bb.0:
130 ; SOFTFLOAT-NEXT: pushq %rax
131 ; SOFTFLOAT-NEXT: movzwl (%rdi), %edi
132 ; SOFTFLOAT-NEXT: callq __gnu_h2f_ieee@PLT
133 ; SOFTFLOAT-NEXT: movl %eax, %edi
134 ; SOFTFLOAT-NEXT: callq __extendsfdf2@PLT
135 ; SOFTFLOAT-NEXT: popq %rcx
136 ; SOFTFLOAT-NEXT: retq
137 %1 = load i16, ptr %src, align 2
138 %2 = tail call double @llvm.convert.from.fp16.f64(i16 %1)
142 define i16 @test5(double %src) nounwind {
143 ; LIBCALL-LABEL: test5:
145 ; LIBCALL-NEXT: pushq %rax
146 ; LIBCALL-NEXT: callq __truncdfhf2@PLT
147 ; LIBCALL-NEXT: pextrw $0, %xmm0, %eax
148 ; LIBCALL-NEXT: # kill: def $ax killed $ax killed $eax
149 ; LIBCALL-NEXT: popq %rcx
154 ; F16C-NEXT: pushq %rax
155 ; F16C-NEXT: callq __truncdfhf2@PLT
156 ; F16C-NEXT: vpextrw $0, %xmm0, %eax
157 ; F16C-NEXT: # kill: def $ax killed $ax killed $eax
158 ; F16C-NEXT: popq %rcx
161 ; SOFTFLOAT-LABEL: test5:
162 ; SOFTFLOAT: # %bb.0:
163 ; SOFTFLOAT-NEXT: pushq %rax
164 ; SOFTFLOAT-NEXT: callq __truncdfhf2@PLT
165 ; SOFTFLOAT-NEXT: popq %rcx
166 ; SOFTFLOAT-NEXT: retq
167 %val = tail call i16 @llvm.convert.to.fp16.f64(double %src)
171 declare float @llvm.convert.from.fp16.f32(i16) nounwind readnone
172 declare i16 @llvm.convert.to.fp16.f32(float) nounwind readnone
173 declare double @llvm.convert.from.fp16.f64(i16) nounwind readnone
174 declare i16 @llvm.convert.to.fp16.f64(double) nounwind readnone