[PATCH] D135124: Add f16 nearbyint support.

Leon Clark via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 3 20:29:36 PDT 2022


Leonc created this revision.
Herald added subscribers: kosarev, foad, kerbowa, hiraditya, nhaehnle, jvesely, arsenm.
Herald added a project: All.
Leonc requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Enable lowering of FNEARBYINT for f16 and extend existing tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135124

Files:
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
  llvm/test/CodeGen/AMDGPU/fnearbyint.ll


Index: llvm/test/CodeGen/AMDGPU/fnearbyint.ll
===================================================================
--- llvm/test/CodeGen/AMDGPU/fnearbyint.ll
+++ llvm/test/CodeGen/AMDGPU/fnearbyint.ll
@@ -5,6 +5,7 @@
 ; This should have the exactly the same output as the test for rint,
 ; so no need to check anything.
 
+declare half @llvm.nearbyint.f16(half) #0
 declare float @llvm.nearbyint.f32(float) #0
 declare <2 x float> @llvm.nearbyint.v2f32(<2 x float>) #0
 declare <4 x float> @llvm.nearbyint.v4f32(<4 x float>) #0
@@ -13,6 +14,12 @@
 declare <4 x double> @llvm.nearbyint.v4f64(<4 x double>) #0
 
 
+define amdgpu_kernel void @fnearbyint_f16(half addrspace(1)* %out, half %in) #1 {
+  %1 = call half @llvm.nearbyint.f16(half %in)
+  store half %1, half addrspace(1)* %out
+  ret void
+}
+
 define amdgpu_kernel void @fnearbyint_f32(float addrspace(1)* %out, float %in) #1 {
 entry:
   %0 = call float @llvm.nearbyint.f32(float %in)
Index: llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
@@ -302,7 +302,7 @@
 
   setOperationAction({ISD::FLOG, ISD::FLOG10, ISD::FEXP}, MVT::f32, Custom);
 
-  setOperationAction(ISD::FNEARBYINT, {MVT::f32, MVT::f64}, Custom);
+  setOperationAction(ISD::FNEARBYINT, {MVT::f16, MVT::f32, MVT::f64}, Custom);
 
   setOperationAction(ISD::FREM, {MVT::f16, MVT::f32, MVT::f64}, Custom);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135124.464879.patch
Type: text/x-patch
Size: 1495 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221004/b87c6064/attachment.bin>


More information about the llvm-commits mailing list