[RISCV] Add inline expansion for vector ftrunc/fceil/ffloor.
authorCraig Topper <craig.topper@sifive.com>
Wed, 1 Dec 2021 18:46:30 +0000 (10:46 -0800)
committerCraig Topper <craig.topper@sifive.com>
Wed, 1 Dec 2021 19:25:28 +0000 (11:25 -0800)
commit2f6beb7b0e9e7ade6fd5ebc54c0fde5ddad0ef19
tree2ae930e95cbcfdb5ddb53cc094b4552e0735a293
parent44bc97c834443c791eb476c9c96aa03b527a5a18
[RISCV] Add inline expansion for vector ftrunc/fceil/ffloor.

This prevents scalarization of fixed vector operations or crashes
on scalable vectors.

We don't have direct support for these operations. To emulate
ftrunc we can convert to the same sized integer and back to fp using
round to zero. We don't need to do a convert if the value is large
enough to have no fractional bits or is a nan.

The ceil and floor lowering would be better if we changed FRM, but
we don't model FRM correctly yet. So I've used the trunc lowering
with a conditional add or subtract with 1.0 if the truncate rounded
in the wrong direction.

There are also missed opportunities to use masked instructions.

Reviewed By: frasercrmck

Differential Revision: https://reviews.llvm.org/D113543
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rvv/fceil-sdnode.ll [new file with mode: 0644]
llvm/test/CodeGen/RISCV/rvv/ffloor-sdnode.ll [new file with mode: 0644]
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp.ll
llvm/test/CodeGen/RISCV/rvv/ftrunc-sdnode.ll [new file with mode: 0644]