From 7bbf5786d76b3d862e30938ce56d3ea7a814e8a3 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Fri, 18 Jul 2014 08:30:10 +0000 Subject: [PATCH] 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 --- lib/Target/NVPTX/NVPTXIntrinsics.td | 5 ++++ test/CodeGen/NVPTX/fp16.ll | 45 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 test/CodeGen/NVPTX/fp16.ll diff --git a/lib/Target/NVPTX/NVPTXIntrinsics.td b/lib/Target/NVPTX/NVPTXIntrinsics.td index 13f6532a857..14e51aa309e 100644 --- a/lib/Target/NVPTX/NVPTXIntrinsics.td +++ b/lib/Target/NVPTX/NVPTXIntrinsics.td @@ -799,6 +799,11 @@ def : Pat<(i16 (fp_to_f16 Float32Regs:$a)), def : Pat<(i16 (fp_to_f16 Float32Regs:$a)), (CVT_f16_f32 Float32Regs:$a, CvtRN)>; +def : Pat<(f64 (f16_to_fp Int16Regs:$a)), + (CVT_f64_f16 Int16Regs:$a, CvtNONE)>; +def : Pat<(i16 (fp_to_f16 Float64Regs:$a)), + (CVT_f16_f64 Float64Regs:$a, CvtRN)>; + // // Bitcast // diff --git a/test/CodeGen/NVPTX/fp16.ll b/test/CodeGen/NVPTX/fp16.ll new file mode 100644 index 00000000000..8770399f2ec --- /dev/null +++ b/test/CodeGen/NVPTX/fp16.ll @@ -0,0 +1,45 @@ +; RUN: llc -march=nvptx -verify-machineinstrs < %s | FileCheck %s + +declare float @llvm.convert.from.fp16.f32(i16) nounwind readnone +declare double @llvm.convert.from.fp16.f64(i16) nounwind readnone +declare i16 @llvm.convert.to.fp16.f32(float) nounwind readnone +declare i16 @llvm.convert.to.fp16.f64(double) nounwind readnone + +; CHECK-LABEL: @test_convert_fp16_to_fp32 +; CHECK: cvt.f32.f16 +define void @test_convert_fp16_to_fp32(float addrspace(1)* noalias %out, i16 addrspace(1)* noalias %in) nounwind { + %val = load i16 addrspace(1)* %in, align 2 + %cvt = call float @llvm.convert.from.fp16.f32(i16 %val) nounwind readnone + store float %cvt, float addrspace(1)* %out, align 4 + ret void +} + + +; CHECK-LABEL: @test_convert_fp16_to_fp64 +; CHECK: cvt.f64.f16 +define void @test_convert_fp16_to_fp64(double addrspace(1)* noalias %out, i16 addrspace(1)* noalias %in) nounwind { + %val = load i16 addrspace(1)* %in, align 2 + %cvt = call double @llvm.convert.from.fp16.f64(i16 %val) nounwind readnone + store double %cvt, double addrspace(1)* %out, align 4 + ret void +} + + +; CHECK-LABEL: @test_convert_fp32_to_fp16 +; CHECK: cvt.rn.f16.f32 +define void @test_convert_fp32_to_fp16(i16 addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind { + %val = load float addrspace(1)* %in, align 2 + %cvt = call i16 @llvm.convert.to.fp16.f32(float %val) nounwind readnone + store i16 %cvt, i16 addrspace(1)* %out, align 4 + ret void +} + + +; CHECK-LABEL: @test_convert_fp64_to_fp16 +; CHECK: cvt.rn.f16.f64 +define void @test_convert_fp64_to_fp16(i16 addrspace(1)* noalias %out, double addrspace(1)* noalias %in) nounwind { + %val = load double addrspace(1)* %in, align 2 + %cvt = call i16 @llvm.convert.to.fp16.f64(double %val) nounwind readnone + store i16 %cvt, i16 addrspace(1)* %out, align 4 + ret void +} -- 2.34.1