[RISCV] Add strictfp support for compares.
authorCraig Topper <craig.topper@sifive.com>
Wed, 12 Jan 2022 04:01:40 +0000 (20:01 -0800)
committerCraig Topper <craig.topper@sifive.com>
Wed, 12 Jan 2022 04:01:41 +0000 (20:01 -0800)
commit63b17eb9ec106540ee5cb91d285027512072a050
tree8405081620e261286a1ba375f56a445c3e47ec99
parent248d55af3e446ad69a64f08cfcc4879f9690e580
[RISCV] Add strictfp support for compares.

This adds support for STRICT_FSETCC(quiet) and STRICT_FSETCCS(signaling).

FEQ matches well to STRICT_FSETCC oeq.
FLT/FLE matches well to STRICT_FSETCCS olt/ole.

Others require commuting operands or multiple instructions.

STRICT_FSETCC olt/ole/ogt/oge/ult/ule/ugt/uge uses FLT/FLE,
but we need to save/restore FFLAGS around them to avoid spurious
exceptions. I've implemented pseudo instructions with a
CustomInserter to insert the save/restore CSR instructions.
Unfortunately, this doesn't honor exceptions for signaling NANs
but I'm not sure if signaling nans are really supported by the
constrained intrinsics.

STRICT_FSETCC one and ueq expand to a pair of FLT instructions
with a save/restore of fflags around each. This could be improved
in the future.

There may be some opportunities to generate better code for strict
comparisons mixed with nonans fast math flags. I've left FIXMEs in
the .td files for that.

Co-Authored-by: ShihPo Hung <shihpo.hung@sifive.com>
Reviewed By: arcbbb

Differential Revision: https://reviews.llvm.org/D116694
llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/lib/Target/RISCV/RISCVInstrFormats.td
llvm/lib/Target/RISCV/RISCVInstrInfo.td
llvm/lib/Target/RISCV/RISCVInstrInfoD.td
llvm/lib/Target/RISCV/RISCVInstrInfoF.td
llvm/lib/Target/RISCV/RISCVInstrInfoZfh.td
llvm/test/CodeGen/RISCV/double-fcmp-strict.ll [new file with mode: 0644]
llvm/test/CodeGen/RISCV/float-fcmp-strict.ll [new file with mode: 0644]
llvm/test/CodeGen/RISCV/half-fcmp-strict.ll [new file with mode: 0644]