@@ -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,7 @@ 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: return lowerConstantFP (Op, DAG);
1358
1361
}
1359
1362
return SDValue ();
1360
1363
}
@@ -3015,6 +3018,30 @@ SDValue MipsTargetLowering::lowerFP_TO_SINT(SDValue Op,
3015
3018
return DAG.getNode (ISD::BITCAST, SDLoc (Op), Op.getValueType (), Trunc);
3016
3019
}
3017
3020
3021
+ SDValue MipsTargetLowering::lowerConstantFP (SDValue Op,
3022
+ SelectionDAG &DAG) const {
3023
+ SDLoc DL (Op);
3024
+ EVT VT = Op.getSimpleValueType ();
3025
+ SDNode *N = Op.getNode ();
3026
+ ConstantFPSDNode *CFP = cast<ConstantFPSDNode >(N);
3027
+
3028
+ if (!CFP->isNaN () || Subtarget.isNaN2008 ()) {
3029
+ return SDValue ();
3030
+ }
3031
+
3032
+ APFloat NaNValue = CFP->getValueAPF ();
3033
+ auto &Sem = NaNValue.getSemantics ();
3034
+
3035
+ // The MSB of the mantissa should be zero for QNaNs in the MIPS legacy NaN
3036
+ // encodings, and one for sNaNs. Check every NaN constants and make sure
3037
+ // they are correctly encoded for legacy encodings.
3038
+ if (!NaNValue.isSignaling ()) {
3039
+ APFloat RealQNaN = NaNValue.getSNaN (Sem);
3040
+ return DAG.getConstantFP (RealQNaN, DL, VT);
3041
+ }
3042
+ return SDValue ();
3043
+ }
3044
+
3018
3045
// ===----------------------------------------------------------------------===//
3019
3046
// Calling Convention Implementation
3020
3047
// ===----------------------------------------------------------------------===//
0 commit comments