@@ -8675,7 +8675,7 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
86758675 // Degenerated cases.
86768676 if (Test == fcNone)
86778677 return DAG.getBoolConstant (false , DL, ResultVT, OperandVT);
8678- if (( Test & fcAllFlags) == fcAllFlags)
8678+ if (Test == fcAllFlags)
86798679 return DAG.getBoolConstant (true , DL, ResultVT, OperandVT);
86808680
86818681 // PPC double double is a pair of doubles, of which the higher part determines
@@ -8686,14 +8686,6 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
86868686 OperandVT = MVT::f64 ;
86878687 }
86888688
8689- // Some checks may be represented as inversion of simpler check, for example
8690- // "inf|normal|subnormal|zero" => !"nan".
8691- bool IsInverted = false ;
8692- if (FPClassTest InvertedCheck = invertFPClassTestIfSimpler (Test)) {
8693- IsInverted = true ;
8694- Test = InvertedCheck;
8695- }
8696-
86978689 // Floating-point type properties.
86988690 EVT ScalarFloatVT = OperandVT.getScalarType ();
86998691 const Type *FloatTy = ScalarFloatVT.getTypeForEVT (*DAG.getContext ());
@@ -8705,9 +8697,16 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
87058697 if (Flags.hasNoFPExcept () &&
87068698 isOperationLegalOrCustom (ISD::SETCC, OperandVT.getScalarType ())) {
87078699 FPClassTest FPTestMask = Test;
8700+ bool IsInvertedFP = false ;
8701+
8702+ if (FPClassTest InvertedFPCheck =
8703+ invertFPClassTestIfSimpler (FPTestMask, true )) {
8704+ FPTestMask = InvertedFPCheck;
8705+ IsInvertedFP = true ;
8706+ }
87088707
8709- ISD::CondCode OrderedCmpOpcode = IsInverted ? ISD::SETUNE : ISD::SETOEQ;
8710- ISD::CondCode UnorderedCmpOpcode = IsInverted ? ISD::SETONE : ISD::SETUEQ;
8708+ ISD::CondCode OrderedCmpOpcode = IsInvertedFP ? ISD::SETUNE : ISD::SETOEQ;
8709+ ISD::CondCode UnorderedCmpOpcode = IsInvertedFP ? ISD::SETONE : ISD::SETUEQ;
87118710
87128711 // See if we can fold an | fcNan into an unordered compare.
87138712 FPClassTest OrderedFPTestMask = FPTestMask & ~fcNan;
@@ -8720,7 +8719,7 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
87208719 const bool IsOrdered = FPTestMask == OrderedFPTestMask;
87218720
87228721 if (std::optional<bool > IsCmp0 =
8723- isFCmpEqualZero (Test , Semantics, DAG.getMachineFunction ());
8722+ isFCmpEqualZero (FPTestMask , Semantics, DAG.getMachineFunction ());
87248723 IsCmp0 && (isCondCodeLegalOrCustom (
87258724 *IsCmp0 ? OrderedCmpOpcode : UnorderedCmpOpcode,
87268725 OperandVT.getScalarType ().getSimpleVT ()))) {
@@ -8732,31 +8731,35 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
87328731 *IsCmp0 ? OrderedCmpOpcode : UnorderedCmpOpcode);
87338732 }
87348733
8735- if (Test == fcNan &&
8736- isCondCodeLegalOrCustom (IsInverted ? ISD::SETO : ISD::SETUO,
8737- OperandVT.getScalarType ().getSimpleVT ())) {
8734+ if (FPTestMask == fcNan &&
8735+ isCondCodeLegalOrCustom (IsInvertedFP ? ISD::SETO : ISD::SETUO,
8736+ OperandVT.getScalarType ().getSimpleVT ()))
87388737 return DAG.getSetCC (DL, ResultVT, Op, Op,
8739- IsInverted ? ISD::SETO : ISD::SETUO);
8740- }
8738+ IsInvertedFP ? ISD::SETO : ISD::SETUO);
87418739
8742- if (Test == fcInf &&
8743- isCondCodeLegalOrCustom (IsInverted ? ISD::SETUNE : ISD::SETOEQ,
8740+ bool IsOrderedInf = FPTestMask == fcInf;
8741+ if ((FPTestMask == fcInf || FPTestMask == (fcInf | fcNan)) &&
8742+ isCondCodeLegalOrCustom (IsOrderedInf ? OrderedCmpOpcode
8743+ : UnorderedCmpOpcode,
87448744 OperandVT.getScalarType ().getSimpleVT ()) &&
8745- isOperationLegalOrCustom (ISD::FABS, OperandVT.getScalarType ())) {
8745+ isOperationLegalOrCustom (ISD::FABS, OperandVT.getScalarType ()) &&
8746+ (isOperationLegal (ISD::ConstantFP, OperandVT.getScalarType ()) ||
8747+ (OperandVT.isVector () &&
8748+ isOperationLegalOrCustom (ISD::BUILD_VECTOR, OperandVT)))) {
87468749 // isinf(x) --> fabs(x) == inf
87478750 SDValue Abs = DAG.getNode (ISD::FABS, DL, OperandVT, Op);
87488751 SDValue Inf =
87498752 DAG.getConstantFP (APFloat::getInf (Semantics), DL, OperandVT);
87508753 return DAG.getSetCC (DL, ResultVT, Abs, Inf,
8751- IsInverted ? ISD::SETUNE : ISD::SETOEQ );
8754+ IsOrderedInf ? OrderedCmpOpcode : UnorderedCmpOpcode );
87528755 }
87538756
87548757 if (OrderedFPTestMask == (fcSubnormal | fcZero) && !IsOrdered) {
87558758 // TODO: Could handle ordered case, but it produces worse code for
87568759 // x86. Maybe handle ordered if fabs is free?
87578760
8758- ISD::CondCode OrderedOp = IsInverted ? ISD::SETUGE : ISD::SETOLT;
8759- ISD::CondCode UnorderedOp = IsInverted ? ISD::SETOGE : ISD::SETULT;
8761+ ISD::CondCode OrderedOp = IsInvertedFP ? ISD::SETUGE : ISD::SETOLT;
8762+ ISD::CondCode UnorderedOp = IsInvertedFP ? ISD::SETOGE : ISD::SETULT;
87608763
87618764 if (isCondCodeLegalOrCustom (IsOrdered ? OrderedOp : UnorderedOp,
87628765 OperandVT.getScalarType ().getSimpleVT ())) {
@@ -8773,6 +8776,15 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
87738776 }
87748777 }
87758778
8779+ // Some checks may be represented as inversion of simpler check, for example
8780+ // "inf|normal|subnormal|zero" => !"nan".
8781+ bool IsInverted = false ;
8782+
8783+ if (FPClassTest InvertedCheck = invertFPClassTestIfSimpler (Test, false )) {
8784+ Test = InvertedCheck;
8785+ IsInverted = true ;
8786+ }
8787+
87768788 // In the general case use integer operations.
87778789 unsigned BitSize = OperandVT.getScalarSizeInBits ();
87788790 EVT IntVT = EVT::getIntegerVT (*DAG.getContext (), BitSize);
0 commit comments