[RISCV] Pass 'half' in the lower 16 bits of an f32 value when F extension is enabled...
authorCraig Topper <craig.topper@sifive.com>
Tue, 30 Mar 2021 16:34:56 +0000 (09:34 -0700)
committerCraig Topper <craig.topper@sifive.com>
Tue, 30 Mar 2021 16:47:54 +0000 (09:47 -0700)
commita33fcafaf0493fe30106be099070a96d10882e9d
treef44520602c28f7403839543c6af5902a374eeaa5
parentf5e9be6fdbdbe2a11f0227963fd4c15e3c319a44
[RISCV] Pass 'half' in the lower 16 bits of an f32 value when F extension is enabled, but Zfh is not.

Without Zfh the half type isn't legal, but it could still be
used as an argument/return in IR. Clang will not generate this today.

Previously we promoted the half value to float for arguments and
returns if the F extension is enabled but Zfh isn't. Then depending on
which ABI is enabled we would pass it in either an FPR or a GPR in
float format.

If the F extension isn't enabled, it would get passed in the lower
16 bits of a GPR in half format.

With this patch the value will always in half format and will be
in the lower bits of a GPR or FPR. This should be consistent
with where the bits are located when Zfh is enabled.

I've based this implementation off of how this is done on ARM.

I've manually nan-boxed the value to 32 bits using integer ops.
It looks like flw, fsw, fmv.s, fmv.w.x, fmf.x.w won't
canonicalize nans so should leave the value alone. I think those
are the instructions that could get used on this value.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D98670
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/calling-conv-half.ll [new file with mode: 0644]
llvm/test/CodeGen/RISCV/copysign-casts.ll