[RISCV] Use softPromoteHalf legalization for fp16 without Zfh rather than PromoteFloat.
authorCraig Topper <craig.topper@sifive.com>
Thu, 1 Apr 2021 18:47:11 +0000 (11:47 -0700)
committerCraig Topper <craig.topper@sifive.com>
Thu, 1 Apr 2021 19:41:57 +0000 (12:41 -0700)
commitdbbc95e3e5aa09928ed4531f7ca01dd979cabab7
tree6dd2b30d1b5286e55a5f65cdfd413e40b44ccc53
parentd4e9fe813f4fabc260f8e859cf2846cb34e0ad3b
[RISCV] Use softPromoteHalf legalization for fp16 without Zfh rather than PromoteFloat.

The default legalization strategy is PromoteFloat which keeps
half in single precision format through multiple floating point
operations. Conversion to/from float is done at loads, stores,
bitcasts, and other places that care about the exact size being 16
bits.

This patches switches to the alternative method softPromoteHalf.
This aims to keep the type in 16-bit format between every operation.
So we promote to float and immediately round for any arithmetic
operation. This should be closer to the IR semantics since we
are rounding after each operation and not accumulating extra
precision across multiple operations. X86 is the only other
target that enables this today. See https://reviews.llvm.org/D73749

I had to update getRegisterTypeForCallingConv to force f16 to
use f32 when the F extension is enabled. This way we can still
pass it in the lower bits of an FPR for ilp32f and lp64f ABIs.
The softPromoteHalf would otherwise always give i16 as the
argument type.

Reviewed By: asb, frasercrmck

Differential Revision: https://reviews.llvm.org/D99148
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.h
llvm/test/CodeGen/RISCV/calling-conv-half.ll
llvm/test/CodeGen/RISCV/copysign-casts.ll
llvm/test/CodeGen/RISCV/fp16-promote.ll
llvm/test/CodeGen/RISCV/half-bitmanip-dagcombines.ll
llvm/test/CodeGen/RISCV/rv32i-rv64i-half.ll