Skip to content

Commit f720647

Browse files
committed
[RISCV] Support Bit-Preserving FP in F/D Extensions
Summary: This allows some integer bitwise operations to instead be performed by hardware fp instructions. This is correct because the RISC-V spec requires the F and D extensions to use the IEEE-754 standard representation, and fp register loads and stores to be bit-preserving. This is tested against the soft-float ABI, but with hardware float extensions enabled, so that the tests also ensure the optimisation also fires in this case. Reviewers: asb, luismarques Reviewed By: asb Subscribers: hiraditya, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, kito-cheng, shiva0217, jrtc27, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, PkmX, jocewei, psnobl, benna, Jim, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62900 llvm-svn: 362790
1 parent cb8de55 commit f720647

File tree

3 files changed

+397
-0
lines changed

3 files changed

+397
-0
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ bool RISCVTargetLowering::isSExtCheaperThanZExt(EVT SrcVT, EVT DstVT) const {
302302
return Subtarget.is64Bit() && SrcVT == MVT::i32 && DstVT == MVT::i64;
303303
}
304304

305+
bool RISCVTargetLowering::hasBitPreservingFPLogic(EVT VT) const {
306+
return (VT == MVT::f32 && Subtarget.hasStdExtF()) ||
307+
(VT == MVT::f64 && Subtarget.hasStdExtD());
308+
}
309+
305310
// Changes the condition code and swaps operands if necessary, so the SetCC
306311
// operation matches one of the comparisons supported directly in the RISC-V
307312
// ISA.

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class RISCVTargetLowering : public TargetLowering {
7272
bool isZExtFree(SDValue Val, EVT VT2) const override;
7373
bool isSExtCheaperThanZExt(EVT SrcVT, EVT DstVT) const override;
7474

75+
bool hasBitPreservingFPLogic(EVT VT) const override;
76+
7577
// Provide custom lowering hooks for some operations.
7678
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
7779
void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,

0 commit comments

Comments
 (0)