[llvm] r287203 - [AMDGPU] Custom lower f16 = fp_round f64
Konstantin Zhuravlyov via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 16 20:28:37 PST 2016
Author: kzhuravl
Date: Wed Nov 16 22:28:37 2016
New Revision: 287203
URL: http://llvm.org/viewvc/llvm-project?rev=287203&view=rev
Log:
[AMDGPU] Custom lower f16 = fp_round f64
Modified:
llvm/trunk/lib/Target/AMDGPU/SIISelLowering.cpp
llvm/trunk/lib/Target/AMDGPU/SIISelLowering.h
Modified: llvm/trunk/lib/Target/AMDGPU/SIISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIISelLowering.cpp?rev=287203&r1=287202&r2=287203&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/SIISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/SIISelLowering.cpp Wed Nov 16 22:28:37 2016
@@ -285,6 +285,7 @@ SITargetLowering::SITargetLowering(const
AddPromotedToType(ISD::STORE, MVT::f16, MVT::i16);
// F16 - VOP1 Actions.
+ setOperationAction(ISD::FP_ROUND, MVT::f16, Custom);
setOperationAction(ISD::FCOS, MVT::f16, Promote);
setOperationAction(ISD::FSIN, MVT::f16, Promote);
setOperationAction(ISD::FP_TO_SINT, MVT::f16, Promote);
@@ -1832,6 +1833,8 @@ SDValue SITargetLowering::LowerOperation
case ISD::ConstantFP:
return lowerConstantFP(Op, DAG);
+ case ISD::FP_ROUND:
+ return lowerFP_ROUND(Op, DAG);
}
return SDValue();
}
@@ -2043,6 +2046,23 @@ SDValue SITargetLowering::lowerConstantF
return SDValue();
}
+SDValue SITargetLowering::lowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const {
+ EVT DstVT = Op.getValueType();
+ EVT SrcVT = Op.getOperand(0).getValueType();
+
+ assert(DstVT == MVT::f16 &&
+ "Do not know how to custom lower FP_ROUND for non-f16 type");
+
+ if (SrcVT != MVT::f64)
+ return Op;
+
+ SDLoc DL(Op);
+ SDValue Src = Op.getOperand(0);
+ SDValue FpToFp16 = DAG.getNode(ISD::FP_TO_FP16, DL, MVT::i32, Src);
+ SDValue Trunc = DAG.getNode(ISD::TRUNCATE, DL, MVT::i16, FpToFp16);
+ return DAG.getNode(ISD::BITCAST, DL, MVT::f16, Trunc);;
+}
+
SDValue SITargetLowering::getSegmentAperture(unsigned AS,
SelectionDAG &DAG) const {
SDLoc SL;
Modified: llvm/trunk/lib/Target/AMDGPU/SIISelLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIISelLowering.h?rev=287203&r1=287202&r2=287203&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/SIISelLowering.h (original)
+++ llvm/trunk/lib/Target/AMDGPU/SIISelLowering.h Wed Nov 16 22:28:37 2016
@@ -56,6 +56,9 @@ class SITargetLowering final : public AM
/// \brief Custom lowering for ISD::ConstantFP.
SDValue lowerConstantFP(SDValue Op, SelectionDAG &DAG) const;
+ /// \brief Custom lowering for ISD::FP_ROUND for MVT::f16.
+ SDValue lowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
+
SDValue getSegmentAperture(unsigned AS, SelectionDAG &DAG) const;
SDValue lowerADDRSPACECAST(SDValue Op, SelectionDAG &DAG) const;
SDValue lowerTRAP(SDValue Op, SelectionDAG &DAG) const;
More information about the llvm-commits
mailing list