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: vpmovzxwq {{.*#+}} xmm0 = xmm0[0],zero,zero,zero,xmm0[1],zero,zero,zero
93 ; F16C-NEXT: vcvtph2ps %xmm0, %xmm0
96 ; SOFTFLOAT-LABEL: test3:
98 ; SOFTFLOAT-NEXT: pushq %rax
99 ; SOFTFLOAT-NEXT: .cfi_def_cfa_offset 16
100 ; SOFTFLOAT-NEXT: callq __gnu_f2h_ieee@PLT
101 ; SOFTFLOAT-NEXT: movzwl %ax, %edi
102 ; SOFTFLOAT-NEXT: callq __gnu_h2f_ieee@PLT
103 ; SOFTFLOAT-NEXT: popq %rcx
104 ; SOFTFLOAT-NEXT: .cfi_def_cfa_offset 8
105 ; SOFTFLOAT-NEXT: retq
106 %1 = tail call i16 @llvm.convert.to.fp16.f32(float %src)
107 %2 = tail call float @llvm.convert.from.fp16.f32(i16 %1)
111 define double @test4(ptr nocapture %src) nounwind {
112 ; LIBCALL-LABEL: test4:
114 ; LIBCALL-NEXT: pushq %rax
115 ; LIBCALL-NEXT: pinsrw $0, (%rdi), %xmm0
116 ; LIBCALL-NEXT: callq __extendhfsf2@PLT
117 ; LIBCALL-NEXT: cvtss2sd %xmm0, %xmm0
118 ; LIBCALL-NEXT: popq %rax
123 ; F16C-NEXT: movzwl (%rdi), %eax
124 ; F16C-NEXT: vmovd %eax, %xmm0
125 ; F16C-NEXT: vcvtph2ps %xmm0, %xmm0
126 ; F16C-NEXT: vcvtss2sd %xmm0, %xmm0, %xmm0
129 ; SOFTFLOAT-LABEL: test4:
130 ; SOFTFLOAT: # %bb.0:
131 ; SOFTFLOAT-NEXT: pushq %rax
132 ; SOFTFLOAT-NEXT: movzwl (%rdi), %edi
133 ; SOFTFLOAT-NEXT: callq __gnu_h2f_ieee@PLT
134 ; SOFTFLOAT-NEXT: movl %eax, %edi
135 ; SOFTFLOAT-NEXT: callq __extendsfdf2@PLT
136 ; SOFTFLOAT-NEXT: popq %rcx
137 ; SOFTFLOAT-NEXT: retq
138 %1 = load i16, ptr %src, align 2
139 %2 = tail call double @llvm.convert.from.fp16.f64(i16 %1)
143 define i16 @test5(double %src) nounwind {
144 ; LIBCALL-LABEL: test5:
146 ; LIBCALL-NEXT: pushq %rax
147 ; LIBCALL-NEXT: callq __truncdfhf2@PLT
148 ; LIBCALL-NEXT: pextrw $0, %xmm0, %eax
149 ; LIBCALL-NEXT: # kill: def $ax killed $ax killed $eax
150 ; LIBCALL-NEXT: popq %rcx
155 ; F16C-NEXT: pushq %rax
156 ; F16C-NEXT: callq __truncdfhf2@PLT
157 ; F16C-NEXT: vpextrw $0, %xmm0, %eax
158 ; F16C-NEXT: # kill: def $ax killed $ax killed $eax
159 ; F16C-NEXT: popq %rcx
162 ; SOFTFLOAT-LABEL: test5:
163 ; SOFTFLOAT: # %bb.0:
164 ; SOFTFLOAT-NEXT: pushq %rax
165 ; SOFTFLOAT-NEXT: callq __truncdfhf2@PLT
166 ; SOFTFLOAT-NEXT: popq %rcx
167 ; SOFTFLOAT-NEXT: retq
168 %val = tail call i16 @llvm.convert.to.fp16.f64(double %src)
172 declare float @llvm.convert.from.fp16.f32(i16) nounwind readnone
173 declare i16 @llvm.convert.to.fp16.f32(float) nounwind readnone
174 declare double @llvm.convert.from.fp16.f64(i16) nounwind readnone
175 declare i16 @llvm.convert.to.fp16.f64(double) nounwind readnone