@@ -520,6 +520,9 @@ MipsTargetLowering::MipsTargetLowering(const MipsTargetMachine &TM,
520
520
521
521
setOperationAction (ISD::TRAP, MVT::Other, Legal);
522
522
523
+ setOperationAction (ISD::ConstantFP, MVT::f32, Custom);
524
+ setOperationAction (ISD::ConstantFP, MVT::f64, Custom);
525
+
523
526
setTargetDAGCombine ({ISD::SDIVREM, ISD::UDIVREM, ISD::SELECT, ISD::AND,
524
527
ISD::OR, ISD::ADD, ISD::SUB, ISD::AssertZext, ISD::SHL,
525
528
ISD::SIGN_EXTEND});
@@ -1355,6 +1358,8 @@ LowerOperation(SDValue Op, SelectionDAG &DAG) const
1355
1358
case ISD::FP_TO_SINT: return lowerFP_TO_SINT (Op, DAG);
1356
1359
case ISD::READCYCLECOUNTER:
1357
1360
return lowerREADCYCLECOUNTER (Op, DAG);
1361
+ case ISD::ConstantFP:
1362
+ return lowerConstantFP (Op, DAG);
1358
1363
}
1359
1364
return SDValue ();
1360
1365
}
@@ -3015,6 +3020,30 @@ SDValue MipsTargetLowering::lowerFP_TO_SINT(SDValue Op,
3015
3020
return DAG.getNode (ISD::BITCAST, SDLoc (Op), Op.getValueType (), Trunc);
3016
3021
}
3017
3022
3023
+ SDValue MipsTargetLowering::lowerConstantFP (SDValue Op,
3024
+ SelectionDAG &DAG) const {
3025
+ SDLoc DL (Op);
3026
+ EVT VT = Op.getSimpleValueType ();
3027
+ SDNode *N = Op.getNode ();
3028
+ ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(N);
3029
+
3030
+ if (!CFP->isNaN () || Subtarget.isNaN2008 ()) {
3031
+ return SDValue ();
3032
+ }
3033
+
3034
+ APFloat NaNValue = CFP->getValueAPF ();
3035
+ auto &Sem = NaNValue.getSemantics ();
3036
+
3037
+ // The MSB of the mantissa should be zero for QNaNs in the MIPS legacy NaN
3038
+ // encodings, and one for sNaNs. Check every NaN constants and make sure
3039
+ // they are correctly encoded for legacy encodings.
3040
+ if (!NaNValue.isSignaling ()) {
3041
+ APFloat RealQNaN = NaNValue.getSNaN (Sem);
3042
+ return DAG.getConstantFP (RealQNaN, DL, VT);
3043
+ }
3044
+ return SDValue ();
3045
+ }
3046
+
3018
3047
// ===----------------------------------------------------------------------===//
3019
3048
// Calling Convention Implementation
3020
3049
// ===----------------------------------------------------------------------===//
0 commit comments