diff options
author | Alex Bradbury <asb@igalia.com> | 2023-06-30 16:39:15 +0100 |
---|---|---|
committer | Alex Bradbury <asb@igalia.com> | 2023-06-30 16:41:49 +0100 |
commit | 5ba40c7be35679a26d7b2c29affaad09aabf5e22 (patch) | |
tree | cd49a30be1598aa958d7afe25e51316c4aef815b /llvm/lib/CodeGen/MachineFunction.cpp | |
parent | ee5aaa8e6c3f77925ca92f28cb961c0804986dd7 (diff) | |
download | llvm-5ba40c7be35679a26d7b2c29affaad09aabf5e22.zip llvm-5ba40c7be35679a26d7b2c29affaad09aabf5e22.tar.gz llvm-5ba40c7be35679a26d7b2c29affaad09aabf5e22.tar.bz2 |
[RISCV] Custom lower FP_TO_FP16 and FP16_TO_FP to correct ABI of of libcall
As introduced in D99148, RISC-V uses the softPromoteHalf legalisation
for fp16 values without zfh, with logic ensuring that f16 values are
passed in lower bits of FPRs (see D98670) when F or D support is
present. This legalisation produces ISD::FP_TO_FP16 and ISD::FP16_TO_FP
nodes which (as described in ISDOpcodes.h) provide a "semi-softened
interface for dealing with f16 (as an i16)". i.e. the return type of the
FP_TO_FP16 is an integer rather than a float (and the arg of FP16_TO_FP
is an integer). The remainder of the description focuses primarily on
FP_TO_FP16 for ease of explanation.
FP_TO_FP16 is lowered to a libcall to `__truncsfhf2 (float)` or
`__truncdfhf2 (double)`. As of D92241, `_Float16` is used as the return
type of these libcalls if the host compiler accepts `_Float16` in a test
input (i.e. dst_t is set to `_Float16`). `_Float16` is enabled for the
RISC-V target as of D105001 and so the return value should be passed in
an FPR on hard float ABIs.
This patch fixes the ABI issue in what appears to be a minimally
invasive way - leaving the softPromoteHalf logic undisturbed, and
lowering FP_TO_FP16 to an f32-returning libcall, converting its result
to an XLen integer value.
As can be seen in the test changes, the custom lowering for FP16_TO_FP
means the libcall is no longer tail-callable.
Although this patch fixes the issue, there are two open items:
* Redundant fmv.x.w and fmv.w.x pairs are now somtimes produced during
lowering (not a correctness issue).
* Now coverage for STRICT variants of FP16 conversion opcodes.
Differential Revision: https://reviews.llvm.org/D151284
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunction.cpp')
0 files changed, 0 insertions, 0 deletions