@@ -3578,15 +3578,22 @@ SDValue AMDGPUTargetLowering::LowerFP_TO_FP16(SDValue Op, SelectionDAG &DAG) con
35783578 return SDValue ();
35793579 }
35803580
3581- assert (N0.getSimpleValueType () == MVT::f64 );
3581+ return LowerF64ToF16 (N0, Op.getValueType (), DL, DAG);
3582+ }
3583+
3584+ SDValue AMDGPUTargetLowering::LowerF64ToF16 (SDValue Src, EVT ResTy,
3585+ const SDLoc &DL,
3586+ SelectionDAG &DAG) const {
3587+ assert (Src.getSimpleValueType () == MVT::f64 );
35823588
35833589 // f64 -> f16 conversion using round-to-nearest-even rounding mode.
3590+ // TODO: We can generate better code for True16.
35843591 const unsigned ExpMask = 0x7ff ;
35853592 const unsigned ExpBiasf64 = 1023 ;
35863593 const unsigned ExpBiasf16 = 15 ;
35873594 SDValue Zero = DAG.getConstant (0 , DL, MVT::i32 );
35883595 SDValue One = DAG.getConstant (1 , DL, MVT::i32 );
3589- SDValue U = DAG.getNode (ISD::BITCAST, DL, MVT::i64 , N0 );
3596+ SDValue U = DAG.getNode (ISD::BITCAST, DL, MVT::i64 , Src );
35903597 SDValue UH = DAG.getNode (ISD::SRL, DL, MVT::i64 , U,
35913598 DAG.getConstant (32 , DL, MVT::i64 ));
35923599 UH = DAG.getZExtOrTrunc (UH, DL, MVT::i32 );
@@ -3661,7 +3668,7 @@ SDValue AMDGPUTargetLowering::LowerFP_TO_FP16(SDValue Op, SelectionDAG &DAG) con
36613668 DAG.getConstant (0x8000 , DL, MVT::i32 ));
36623669
36633670 V = DAG.getNode (ISD::OR, DL, MVT::i32 , Sign, V);
3664- return DAG.getZExtOrTrunc (V, DL, Op. getValueType () );
3671+ return DAG.getZExtOrTrunc (V, DL, ResTy );
36653672}
36663673
36673674SDValue AMDGPUTargetLowering::LowerFP_TO_INT (const SDValue Op,
0 commit comments