@@ -450,6 +450,7 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
450450 setOperationAction(ISD::UINT_TO_FP, MVT::i32, Legal);
451451 } else {
452452 // PowerPC turns FP_TO_SINT into FCTIWZ and some load/stores.
453+ setOperationAction(ISD::STRICT_FP_TO_SINT, MVT::i32, Custom);
453454 setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom);
454455
455456 // PowerPC does not have [U|S]INT_TO_FP
@@ -582,12 +583,15 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
582583
583584 if (Subtarget.has64BitSupport()) {
584585 // They also have instructions for converting between i64 and fp.
586+ setOperationAction(ISD::STRICT_FP_TO_SINT, MVT::i64, Custom);
587+ setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::i64, Expand);
585588 setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
586589 setOperationAction(ISD::FP_TO_UINT, MVT::i64, Expand);
587590 setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
588591 setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand);
589592 // This is just the low 32 bits of a (signed) fp->i64 conversion.
590593 // We cannot do this with Promote because i64 is not a legal type.
594+ setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::i32, Custom);
591595 setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom);
592596
593597 if (Subtarget.hasLFIWAX() || Subtarget.isPPC64())
@@ -597,19 +601,25 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
597601 if (Subtarget.hasSPE()) {
598602 setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::i32, Legal);
599603 setOperationAction(ISD::FP_TO_UINT, MVT::i32, Legal);
600- } else
604+ } else {
605+ setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::i32, Expand);
601606 setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand);
607+ }
602608 }
603609
604610 // With the instructions enabled under FPCVT, we can do everything.
605611 if (Subtarget.hasFPCVT()) {
606612 if (Subtarget.has64BitSupport()) {
613+ setOperationAction(ISD::STRICT_FP_TO_SINT, MVT::i64, Custom);
614+ setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::i64, Custom);
607615 setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
608616 setOperationAction(ISD::FP_TO_UINT, MVT::i64, Custom);
609617 setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
610618 setOperationAction(ISD::UINT_TO_FP, MVT::i64, Custom);
611619 }
612620
621+ setOperationAction(ISD::STRICT_FP_TO_SINT, MVT::i32, Custom);
622+ setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::i32, Custom);
613623 setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom);
614624 setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom);
615625 setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom);
@@ -1464,6 +1474,14 @@ const char *PPCTargetLowering::getTargetNodeName(unsigned Opcode) const {
14641474 case PPCISD::MAT_PCREL_ADDR: return "PPCISD::MAT_PCREL_ADDR";
14651475 case PPCISD::LD_SPLAT: return "PPCISD::LD_SPLAT";
14661476 case PPCISD::FNMSUB: return "PPCISD::FNMSUB";
1477+ case PPCISD::STRICT_FCTIDZ:
1478+ return "PPCISD::STRICT_FCTIDZ";
1479+ case PPCISD::STRICT_FCTIWZ:
1480+ return "PPCISD::STRICT_FCTIWZ";
1481+ case PPCISD::STRICT_FCTIDUZ:
1482+ return "PPCISD::STRICT_FCTIDUZ";
1483+ case PPCISD::STRICT_FCTIWUZ:
1484+ return "PPCISD::STRICT_FCTIWUZ";
14671485 }
14681486 return nullptr;
14691487}
@@ -7938,28 +7956,57 @@ SDValue PPCTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const {
79387956 return Op;
79397957}
79407958
7959+ static unsigned getPPCStrictOpcode(unsigned Opc) {
7960+ switch (Opc) {
7961+ default:
7962+ llvm_unreachable("No strict version of this opcode!");
7963+ case PPCISD::FCTIDZ:
7964+ return PPCISD::STRICT_FCTIDZ;
7965+ case PPCISD::FCTIWZ:
7966+ return PPCISD::STRICT_FCTIWZ;
7967+ case PPCISD::FCTIDUZ:
7968+ return PPCISD::STRICT_FCTIDUZ;
7969+ case PPCISD::FCTIWUZ:
7970+ return PPCISD::STRICT_FCTIWUZ;
7971+ }
7972+ }
7973+
79417974static SDValue convertFPToInt(SDValue Op, SelectionDAG &DAG,
79427975 const PPCSubtarget &Subtarget) {
79437976 SDLoc dl(Op);
7944- bool IsSigned = Op.getOpcode() == ISD::FP_TO_SINT;
7945- SDValue Src = Op.getOperand(0);
7977+ bool IsStrict = Op->isStrictFPOpcode();
7978+ bool IsSigned = Op.getOpcode() == ISD::FP_TO_SINT ||
7979+ Op.getOpcode() == ISD::STRICT_FP_TO_SINT;
7980+ // For strict nodes, source is the second operand.
7981+ SDValue Src = Op.getOperand(IsStrict ? 1 : 0);
7982+ SDValue Chain = IsStrict ? Op.getOperand(0) : SDValue();
79467983 assert(Src.getValueType().isFloatingPoint());
7947- if (Src.getValueType() == MVT::f32)
7948- Src = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Src);
7984+ if (Src.getValueType() == MVT::f32) {
7985+ if (IsStrict) {
7986+ Src = DAG.getNode(ISD::STRICT_FP_EXTEND, dl, {MVT::f64, MVT::Other},
7987+ {Chain, Src});
7988+ Chain = Src.getValue(1);
7989+ } else
7990+ Src = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Src);
7991+ }
79497992 SDValue Conv;
7993+ unsigned Opc = ISD::DELETED_NODE;
79507994 switch (Op.getSimpleValueType().SimpleTy) {
79517995 default: llvm_unreachable("Unhandled FP_TO_INT type in custom expander!");
79527996 case MVT::i32:
7953- Conv = DAG.getNode(
7954- IsSigned ? PPCISD::FCTIWZ
7955- : (Subtarget.hasFPCVT() ? PPCISD::FCTIWUZ : PPCISD::FCTIDZ),
7956- dl, MVT::f64, Src);
7997+ Opc = IsSigned ? PPCISD::FCTIWZ
7998+ : (Subtarget.hasFPCVT() ? PPCISD::FCTIWUZ : PPCISD::FCTIDZ);
79577999 break;
79588000 case MVT::i64:
79598001 assert((IsSigned || Subtarget.hasFPCVT()) &&
79608002 "i64 FP_TO_UINT is supported only with FPCVT");
7961- Conv = DAG.getNode(IsSigned ? PPCISD::FCTIDZ : PPCISD::FCTIDUZ, dl,
7962- MVT::f64, Src);
8003+ Opc = IsSigned ? PPCISD::FCTIDZ : PPCISD::FCTIDUZ;
8004+ }
8005+ if (IsStrict) {
8006+ Opc = getPPCStrictOpcode(Opc);
8007+ Conv = DAG.getNode(Opc, dl, {MVT::f64, MVT::Other}, {Chain, Src});
8008+ } else {
8009+ Conv = DAG.getNode(Opc, dl, MVT::f64, Src);
79638010 }
79648011 return Conv;
79658012}
@@ -7968,7 +8015,9 @@ void PPCTargetLowering::LowerFP_TO_INTForReuse(SDValue Op, ReuseLoadInfo &RLI,
79688015 SelectionDAG &DAG,
79698016 const SDLoc &dl) const {
79708017 SDValue Tmp = convertFPToInt(Op, DAG, Subtarget);
7971- bool IsSigned = Op.getOpcode() == ISD::FP_TO_SINT;
8018+ bool IsSigned = Op.getOpcode() == ISD::FP_TO_SINT ||
8019+ Op.getOpcode() == ISD::STRICT_FP_TO_SINT;
8020+ bool IsStrict = Op->isStrictFPOpcode();
79728021
79738022 // Convert the FP value to an int value through memory.
79748023 bool i32Stack = Op.getValueType() == MVT::i32 && Subtarget.hasSTFIWX() &&
@@ -7979,18 +8028,18 @@ void PPCTargetLowering::LowerFP_TO_INTForReuse(SDValue Op, ReuseLoadInfo &RLI,
79798028 MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI);
79808029
79818030 // Emit a store to the stack slot.
7982- SDValue Chain;
8031+ SDValue Chain = IsStrict ? Tmp.getValue(1) : DAG.getEntryNode() ;
79838032 Align Alignment(DAG.getEVTAlign(Tmp.getValueType()));
79848033 if (i32Stack) {
79858034 MachineFunction &MF = DAG.getMachineFunction();
79868035 Alignment = Align(4);
79878036 MachineMemOperand *MMO =
79888037 MF.getMachineMemOperand(MPI, MachineMemOperand::MOStore, 4, Alignment);
7989- SDValue Ops[] = { DAG.getEntryNode() , Tmp, FIPtr };
8038+ SDValue Ops[] = { Chain , Tmp, FIPtr };
79908039 Chain = DAG.getMemIntrinsicNode(PPCISD::STFIWX, dl,
79918040 DAG.getVTList(MVT::Other), Ops, MVT::i32, MMO);
79928041 } else
7993- Chain = DAG.getStore(DAG.getEntryNode() , dl, Tmp, FIPtr, MPI, Alignment);
8042+ Chain = DAG.getStore(Chain , dl, Tmp, FIPtr, MPI, Alignment);
79948043
79958044 // Result is a load from the stack slot. If loading 4 bytes, make sure to
79968045 // add in a bias on big endian.
@@ -8012,23 +8061,29 @@ void PPCTargetLowering::LowerFP_TO_INTForReuse(SDValue Op, ReuseLoadInfo &RLI,
80128061SDValue PPCTargetLowering::LowerFP_TO_INTDirectMove(SDValue Op,
80138062 SelectionDAG &DAG,
80148063 const SDLoc &dl) const {
8015- assert(Op.getOperand(0).getValueType().isFloatingPoint());
8016- return DAG.getNode(PPCISD::MFVSR, dl, Op.getSimpleValueType().SimpleTy,
8017- convertFPToInt(Op, DAG, Subtarget));
8064+ SDValue Conv = convertFPToInt(Op, DAG, Subtarget);
8065+ SDValue Mov = DAG.getNode(PPCISD::MFVSR, dl, Op.getValueType(), Conv);
8066+ if (Op->isStrictFPOpcode())
8067+ return DAG.getMergeValues({Mov, Conv.getValue(1)}, dl);
8068+ else
8069+ return Mov;
80188070}
80198071
80208072SDValue PPCTargetLowering::LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG,
80218073 const SDLoc &dl) const {
8022- SDValue Src = Op.getOperand(0);
8074+ bool IsStrict = Op->isStrictFPOpcode();
8075+ bool IsSigned = Op.getOpcode() == ISD::FP_TO_SINT ||
8076+ Op.getOpcode() == ISD::STRICT_FP_TO_SINT;
8077+ SDValue Src = Op.getOperand(IsStrict ? 1 : 0);
80238078 // FP to INT conversions are legal for f128.
80248079 if (Src.getValueType() == MVT::f128)
80258080 return Op;
80268081
80278082 // Expand ppcf128 to i32 by hand for the benefit of llvm-gcc bootstrap on
80288083 // PPC (the libcall is not available).
8029- if (Src.getValueType() == MVT::ppcf128) {
8084+ if (Src.getValueType() == MVT::ppcf128 && !IsStrict ) {
80308085 if (Op.getValueType() == MVT::i32) {
8031- if (Op.getOpcode() == ISD::FP_TO_SINT ) {
8086+ if (IsSigned ) {
80328087 SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::f64, Src,
80338088 DAG.getIntPtrConstant(0, dl));
80348089 SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::f64, Src,
@@ -8039,8 +8094,7 @@ SDValue PPCTargetLowering::LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG,
80398094
80408095 // Now use a smaller FP_TO_SINT.
80418096 return DAG.getNode(ISD::FP_TO_SINT, dl, MVT::i32, Res);
8042- }
8043- if (Op.getOpcode() == ISD::FP_TO_UINT) {
8097+ } else {
80448098 const uint64_t TwoE31[] = {0x41e0000000000000LL, 0};
80458099 APFloat APF = APFloat(APFloat::PPCDoubleDouble(), APInt(128, TwoE31));
80468100 SDValue Tmp = DAG.getConstantFP(APF, dl, MVT::ppcf128);
@@ -10458,6 +10512,8 @@ SDValue PPCTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
1045810512 case ISD::STORE: return LowerSTORE(Op, DAG);
1045910513 case ISD::TRUNCATE: return LowerTRUNCATE(Op, DAG);
1046010514 case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
10515+ case ISD::STRICT_FP_TO_UINT:
10516+ case ISD::STRICT_FP_TO_SINT:
1046110517 case ISD::FP_TO_UINT:
1046210518 case ISD::FP_TO_SINT: return LowerFP_TO_INT(Op, DAG, SDLoc(Op));
1046310519 case ISD::UINT_TO_FP:
@@ -10548,10 +10604,13 @@ void PPCTargetLowering::ReplaceNodeResults(SDNode *N,
1054810604 }
1054910605 return;
1055010606 }
10607+ case ISD::STRICT_FP_TO_SINT:
10608+ case ISD::STRICT_FP_TO_UINT:
1055110609 case ISD::FP_TO_SINT:
1055210610 case ISD::FP_TO_UINT:
1055310611 // LowerFP_TO_INT() can only handle f32 and f64.
10554- if (N->getOperand(0).getValueType() == MVT::ppcf128)
10612+ if (N->getOperand(N->isStrictFPOpcode() ? 1 : 0).getValueType() ==
10613+ MVT::ppcf128)
1055510614 return;
1055610615 Results.push_back(LowerFP_TO_INT(SDValue(N, 0), DAG, dl));
1055710616 return;
0 commit comments