@@ -467,6 +467,8 @@ MipsTargetLowering::MipsTargetLowering(const MipsTargetMachine &TM,
467
467
setOperationAction (ISD::FMA, MVT::f64 , Expand);
468
468
setOperationAction (ISD::FREM, MVT::f32 , Expand);
469
469
setOperationAction (ISD::FREM, MVT::f64 , Expand);
470
+ setOperationAction (ISD::ConstantFP, MVT::f32 , Custom);
471
+ setOperationAction (ISD::ConstantFP, MVT::f64 , Custom);
470
472
471
473
// Lower f16 conversion operations into library calls
472
474
setOperationAction (ISD::FP16_TO_FP, MVT::f32 , Expand);
@@ -1355,6 +1357,8 @@ LowerOperation(SDValue Op, SelectionDAG &DAG) const
1355
1357
case ISD::FP_TO_SINT: return lowerFP_TO_SINT (Op, DAG);
1356
1358
case ISD::READCYCLECOUNTER:
1357
1359
return lowerREADCYCLECOUNTER (Op, DAG);
1360
+ case ISD::ConstantFP:
1361
+ return lowerConstantFP (Op, DAG);
1358
1362
}
1359
1363
return SDValue ();
1360
1364
}
@@ -3015,6 +3019,30 @@ SDValue MipsTargetLowering::lowerFP_TO_SINT(SDValue Op,
3015
3019
return DAG.getNode (ISD::BITCAST, SDLoc (Op), Op.getValueType (), Trunc);
3016
3020
}
3017
3021
3022
+ SDValue MipsTargetLowering::lowerConstantFP (SDValue Op,
3023
+ SelectionDAG &DAG) const {
3024
+ SDLoc DL (Op);
3025
+ EVT VT = Op.getSimpleValueType ();
3026
+ SDNode *N = Op.getNode ();
3027
+ ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(N);
3028
+
3029
+ if (!CFP->isNaN () || Subtarget.isNaN2008 ()) {
3030
+ return SDValue ();
3031
+ }
3032
+
3033
+ APFloat NaNValue = CFP->getValueAPF ();
3034
+ auto &Sem = NaNValue.getSemantics ();
3035
+
3036
+ // The MSB of the mantissa should be zero for QNaNs in the MIPS legacy NaN
3037
+ // encodings, and one for sNaNs. Check every NaN constants and make sure
3038
+ // they are correctly encoded for legacy encodings.
3039
+ if (!NaNValue.isSignaling ()) {
3040
+ APFloat RealQNaN = NaNValue.getSNaN (Sem);
3041
+ return DAG.getConstantFP (RealQNaN, DL, VT);
3042
+ }
3043
+ return SDValue ();
3044
+ }
3045
+
3018
3046
// ===----------------------------------------------------------------------===//
3019
3047
// Calling Convention Implementation
3020
3048
// ===----------------------------------------------------------------------===//
0 commit comments