llvm.org GIT mirror llvm / 7bbf578
NVPTX: support direct f16 <-> f64 conversions via intrinsics. Clang may well start emitting these soon, and while it may not be directly relevant for OpenCL or GLSL, the instructions were just sitting there waiting to be used. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213356 91177308-0d34-0410-b5e6-96231b3b80d8 Tim Northover 6 years ago
2 changed file(s) with 50 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
797797 (CVT_f16_f32 Float32Regs:$a, CvtRN_FTZ)>, Requires<[doF32FTZ]>;
798798 def : Pat<(i16 (fp_to_f16 Float32Regs:$a)),
799799 (CVT_f16_f32 Float32Regs:$a, CvtRN)>;
800
801 def : Pat<(f64 (f16_to_fp Int16Regs:$a)),
802 (CVT_f64_f16 Int16Regs:$a, CvtNONE)>;
803 def : Pat<(i16 (fp_to_f16 Float64Regs:$a)),
804 (CVT_f16_f64 Float64Regs:$a, CvtRN)>;
800805
801806 //
802807 // Bitcast
0 ; RUN: llc -march=nvptx -verify-machineinstrs < %s | FileCheck %s
1
2 declare float @llvm.convert.from.fp16.f32(i16) nounwind readnone
3 declare double @llvm.convert.from.fp16.f64(i16) nounwind readnone
4 declare i16 @llvm.convert.to.fp16.f32(float) nounwind readnone
5 declare i16 @llvm.convert.to.fp16.f64(double) nounwind readnone
6
7 ; CHECK-LABEL: @test_convert_fp16_to_fp32
8 ; CHECK: cvt.f32.f16
9 define void @test_convert_fp16_to_fp32(float addrspace(1)* noalias %out, i16 addrspace(1)* noalias %in) nounwind {
10 %val = load i16 addrspace(1)* %in, align 2
11 %cvt = call float @llvm.convert.from.fp16.f32(i16 %val) nounwind readnone
12 store float %cvt, float addrspace(1)* %out, align 4
13 ret void
14 }
15
16
17 ; CHECK-LABEL: @test_convert_fp16_to_fp64
18 ; CHECK: cvt.f64.f16
19 define void @test_convert_fp16_to_fp64(double addrspace(1)* noalias %out, i16 addrspace(1)* noalias %in) nounwind {
20 %val = load i16 addrspace(1)* %in, align 2
21 %cvt = call double @llvm.convert.from.fp16.f64(i16 %val) nounwind readnone
22 store double %cvt, double addrspace(1)* %out, align 4
23 ret void
24 }
25
26
27 ; CHECK-LABEL: @test_convert_fp32_to_fp16
28 ; CHECK: cvt.rn.f16.f32
29 define void @test_convert_fp32_to_fp16(i16 addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind {
30 %val = load float addrspace(1)* %in, align 2
31 %cvt = call i16 @llvm.convert.to.fp16.f32(float %val) nounwind readnone
32 store i16 %cvt, i16 addrspace(1)* %out, align 4
33 ret void
34 }
35
36
37 ; CHECK-LABEL: @test_convert_fp64_to_fp16
38 ; CHECK: cvt.rn.f16.f64
39 define void @test_convert_fp64_to_fp16(i16 addrspace(1)* noalias %out, double addrspace(1)* noalias %in) nounwind {
40 %val = load double addrspace(1)* %in, align 2
41 %cvt = call i16 @llvm.convert.to.fp16.f64(double %val) nounwind readnone
42 store i16 %cvt, i16 addrspace(1)* %out, align 4
43 ret void
44 }