@@ -442,14 +442,11 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
442442 setLoadExtAction(ISD::EXTLOAD, MVT::f64, MVT::f32, Expand);
443443
444444 // If we're enabling GP optimizations, use hardware square root
445- if (!Subtarget.hasFSQRT() &&
446- !(TM.Options.UnsafeFPMath && Subtarget.hasFRSQRTE() &&
447- Subtarget.hasFRE()))
445+ if (!Subtarget.hasFSQRT() && !(Subtarget.hasFRSQRTE() && Subtarget.hasFRE()))
448446 setOperationAction(ISD::FSQRT, MVT::f64, Expand);
449447
450448 if (!Subtarget.hasFSQRT() &&
451- !(TM.Options.UnsafeFPMath && Subtarget.hasFRSQRTES() &&
452- Subtarget.hasFRES()))
449+ !(Subtarget.hasFRSQRTES() && Subtarget.hasFRES()))
453450 setOperationAction(ISD::FSQRT, MVT::f32, Expand);
454451
455452 if (Subtarget.hasFCPSGN()) {
@@ -565,16 +562,15 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
565562 setOperationAction(ISD::BITCAST, MVT::i32, Legal);
566563 setOperationAction(ISD::BITCAST, MVT::i64, Legal);
567564 setOperationAction(ISD::BITCAST, MVT::f64, Legal);
568- if (TM.Options.UnsafeFPMath) {
569- setOperationAction(ISD::LRINT, MVT::f64, Legal);
570- setOperationAction(ISD::LRINT, MVT::f32, Legal);
571- setOperationAction(ISD::LLRINT, MVT::f64, Legal);
572- setOperationAction(ISD::LLRINT, MVT::f32, Legal);
573- setOperationAction(ISD::LROUND, MVT::f64, Legal);
574- setOperationAction(ISD::LROUND, MVT::f32, Legal);
575- setOperationAction(ISD::LLROUND, MVT::f64, Legal);
576- setOperationAction(ISD::LLROUND, MVT::f32, Legal);
577- }
565+
566+ setOperationAction(ISD::STRICT_LRINT, MVT::f64, Custom);
567+ setOperationAction(ISD::STRICT_LRINT, MVT::f32, Custom);
568+ setOperationAction(ISD::STRICT_LLRINT, MVT::f64, Custom);
569+ setOperationAction(ISD::STRICT_LLRINT, MVT::f32, Custom);
570+ setOperationAction(ISD::STRICT_LROUND, MVT::f64, Custom);
571+ setOperationAction(ISD::STRICT_LROUND, MVT::f32, Custom);
572+ setOperationAction(ISD::STRICT_LLROUND, MVT::f64, Custom);
573+ setOperationAction(ISD::STRICT_LLROUND, MVT::f32, Custom);
578574 } else {
579575 setOperationAction(ISD::BITCAST, MVT::f32, Expand);
580576 setOperationAction(ISD::BITCAST, MVT::i32, Expand);
@@ -1034,11 +1030,9 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
10341030 setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v2f64, Legal);
10351031
10361032 // The nearbyint variants are not allowed to raise the inexact exception
1037- // so we can only code-gen them with unsafe math.
1038- if (TM.Options.UnsafeFPMath) {
1039- setOperationAction(ISD::FNEARBYINT, MVT::f64, Legal);
1040- setOperationAction(ISD::FNEARBYINT, MVT::f32, Legal);
1041- }
1033+ // so we can only code-gen them with fpexcept.ignore.
1034+ setOperationAction(ISD::STRICT_FNEARBYINT, MVT::f64, Custom);
1035+ setOperationAction(ISD::STRICT_FNEARBYINT, MVT::f32, Custom);
10421036
10431037 setOperationAction(ISD::FFLOOR, MVT::v2f64, Legal);
10441038 setOperationAction(ISD::FCEIL, MVT::v2f64, Legal);
@@ -8911,11 +8905,13 @@ SDValue PPCTargetLowering::LowerINT_TO_FP(SDValue Op,
89118905 // be lost at this stage, but is below the single-precision rounding
89128906 // position.
89138907 //
8914- // However, if -enable-unsafe-fp-math is in effect, accept double
8908+ // However, if afn is in effect, accept double
89158909 // rounding to avoid the extra overhead.
8916- if (Op.getValueType() == MVT::f32 &&
8917- !Subtarget.hasFPCVT() &&
8918- !DAG.getTarget().Options.UnsafeFPMath) {
8910+ // FIXME: Currently INT_TO_FP can't support fast math flags because
8911+ // of nneg flag, thus Op->getFlags().hasApproximateFuncs() is always
8912+ // false.
8913+ if (Op.getValueType() == MVT::f32 && !Subtarget.hasFPCVT() &&
8914+ !Op->getFlags().hasApproximateFuncs()) {
89198915
89208916 // Twiddle input to make sure the low 11 bits are zero. (If this
89218917 // is the case, we are guaranteed the value will fit into the 53 bit
@@ -12759,6 +12755,14 @@ SDValue PPCTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
1275912755 return LowerADDSUBO_CARRY(Op, DAG);
1276012756 case ISD::UCMP:
1276112757 return LowerUCMP(Op, DAG);
12758+ case ISD::STRICT_LRINT:
12759+ case ISD::STRICT_LLRINT:
12760+ case ISD::STRICT_LROUND:
12761+ case ISD::STRICT_LLROUND:
12762+ case ISD::STRICT_FNEARBYINT:
12763+ if (Op->getFlags().hasNoFPExcept())
12764+ return Op;
12765+ return SDValue();
1276212766 }
1276312767}
1276412768
@@ -18707,11 +18711,12 @@ bool PPCTargetLowering::isProfitableToHoist(Instruction *I) const {
1870718711 const Function *F = I->getFunction();
1870818712 const DataLayout &DL = F->getDataLayout();
1870918713 Type *Ty = User->getOperand(0)->getType();
18714+ bool AllowContract = I->getFastMathFlags().allowContract() &&
18715+ User->getFastMathFlags().allowContract();
1871018716
18711- return !(
18712- isFMAFasterThanFMulAndFAdd(*F, Ty) &&
18713- isOperationLegalOrCustom(ISD::FMA, getValueType(DL, Ty)) &&
18714- (Options.AllowFPOpFusion == FPOpFusion::Fast || Options.UnsafeFPMath));
18717+ return !(isFMAFasterThanFMulAndFAdd(*F, Ty) &&
18718+ isOperationLegalOrCustom(ISD::FMA, getValueType(DL, Ty)) &&
18719+ (AllowContract || Options.AllowFPOpFusion == FPOpFusion::Fast));
1871518720 }
1871618721 case Instruction::Load: {
1871718722 // Don't break "store (load float*)" pattern, this pattern will be combined
0 commit comments