@@ -8672,7 +8672,7 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
8672
8672
// Degenerated cases.
8673
8673
if (Test == fcNone)
8674
8674
return DAG.getBoolConstant (false , DL, ResultVT, OperandVT);
8675
- if (( Test & fcAllFlags) == fcAllFlags)
8675
+ if (Test == fcAllFlags)
8676
8676
return DAG.getBoolConstant (true , DL, ResultVT, OperandVT);
8677
8677
8678
8678
// PPC double double is a pair of doubles, of which the higher part determines
@@ -8683,14 +8683,6 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
8683
8683
OperandVT = MVT::f64 ;
8684
8684
}
8685
8685
8686
- // Some checks may be represented as inversion of simpler check, for example
8687
- // "inf|normal|subnormal|zero" => !"nan".
8688
- bool IsInverted = false ;
8689
- if (FPClassTest InvertedCheck = invertFPClassTestIfSimpler (Test)) {
8690
- IsInverted = true ;
8691
- Test = InvertedCheck;
8692
- }
8693
-
8694
8686
// Floating-point type properties.
8695
8687
EVT ScalarFloatVT = OperandVT.getScalarType ();
8696
8688
const Type *FloatTy = ScalarFloatVT.getTypeForEVT (*DAG.getContext ());
@@ -8702,9 +8694,16 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
8702
8694
if (Flags.hasNoFPExcept () &&
8703
8695
isOperationLegalOrCustom (ISD::SETCC, OperandVT.getScalarType ())) {
8704
8696
FPClassTest FPTestMask = Test;
8697
+ bool IsInvertedFP = false ;
8698
+
8699
+ if (FPClassTest InvertedFPCheck =
8700
+ invertFPClassTestIfSimpler (FPTestMask, true )) {
8701
+ FPTestMask = InvertedFPCheck;
8702
+ IsInvertedFP = true ;
8703
+ }
8705
8704
8706
- ISD::CondCode OrderedCmpOpcode = IsInverted ? ISD::SETUNE : ISD::SETOEQ;
8707
- ISD::CondCode UnorderedCmpOpcode = IsInverted ? ISD::SETONE : ISD::SETUEQ;
8705
+ ISD::CondCode OrderedCmpOpcode = IsInvertedFP ? ISD::SETUNE : ISD::SETOEQ;
8706
+ ISD::CondCode UnorderedCmpOpcode = IsInvertedFP ? ISD::SETONE : ISD::SETUEQ;
8708
8707
8709
8708
// See if we can fold an | fcNan into an unordered compare.
8710
8709
FPClassTest OrderedFPTestMask = FPTestMask & ~fcNan;
@@ -8717,7 +8716,7 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
8717
8716
const bool IsOrdered = FPTestMask == OrderedFPTestMask;
8718
8717
8719
8718
if (std::optional<bool > IsCmp0 =
8720
- isFCmpEqualZero (Test , Semantics, DAG.getMachineFunction ());
8719
+ isFCmpEqualZero (FPTestMask , Semantics, DAG.getMachineFunction ());
8721
8720
IsCmp0 && (isCondCodeLegalOrCustom (
8722
8721
*IsCmp0 ? OrderedCmpOpcode : UnorderedCmpOpcode,
8723
8722
OperandVT.getScalarType ().getSimpleVT ()))) {
@@ -8729,31 +8728,32 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
8729
8728
*IsCmp0 ? OrderedCmpOpcode : UnorderedCmpOpcode);
8730
8729
}
8731
8730
8732
- if (Test == fcNan &&
8733
- isCondCodeLegalOrCustom (IsInverted ? ISD::SETO : ISD::SETUO,
8734
- OperandVT.getScalarType ().getSimpleVT ())) {
8731
+ if (FPTestMask == fcNan &&
8732
+ isCondCodeLegalOrCustom (IsInvertedFP ? ISD::SETO : ISD::SETUO,
8733
+ OperandVT.getScalarType ().getSimpleVT ()))
8735
8734
return DAG.getSetCC (DL, ResultVT, Op, Op,
8736
- IsInverted ? ISD::SETO : ISD::SETUO);
8737
- }
8735
+ IsInvertedFP ? ISD::SETO : ISD::SETUO);
8738
8736
8739
- if (Test == fcInf &&
8740
- isCondCodeLegalOrCustom (IsInverted ? ISD::SETUNE : ISD::SETOEQ,
8737
+ bool IsOrderedInf = FPTestMask == fcInf;
8738
+ if ((FPTestMask == fcInf || FPTestMask == (fcInf | fcNan)) &&
8739
+ isCondCodeLegalOrCustom (IsOrderedInf ? OrderedCmpOpcode
8740
+ : UnorderedCmpOpcode,
8741
8741
OperandVT.getScalarType ().getSimpleVT ()) &&
8742
8742
isOperationLegalOrCustom (ISD::FABS, OperandVT.getScalarType ())) {
8743
8743
// isinf(x) --> fabs(x) == inf
8744
8744
SDValue Abs = DAG.getNode (ISD::FABS, DL, OperandVT, Op);
8745
8745
SDValue Inf =
8746
8746
DAG.getConstantFP (APFloat::getInf (Semantics), DL, OperandVT);
8747
8747
return DAG.getSetCC (DL, ResultVT, Abs, Inf,
8748
- IsInverted ? ISD::SETUNE : ISD::SETOEQ );
8748
+ IsOrderedInf ? OrderedCmpOpcode : UnorderedCmpOpcode );
8749
8749
}
8750
8750
8751
8751
if (OrderedFPTestMask == (fcSubnormal | fcZero) && !IsOrdered) {
8752
8752
// TODO: Could handle ordered case, but it produces worse code for
8753
8753
// x86. Maybe handle ordered if fabs is free?
8754
8754
8755
- ISD::CondCode OrderedOp = IsInverted ? ISD::SETUGE : ISD::SETOLT;
8756
- ISD::CondCode UnorderedOp = IsInverted ? ISD::SETOGE : ISD::SETULT;
8755
+ ISD::CondCode OrderedOp = IsInvertedFP ? ISD::SETUGE : ISD::SETOLT;
8756
+ ISD::CondCode UnorderedOp = IsInvertedFP ? ISD::SETOGE : ISD::SETULT;
8757
8757
8758
8758
if (isCondCodeLegalOrCustom (IsOrdered ? OrderedOp : UnorderedOp,
8759
8759
OperandVT.getScalarType ().getSimpleVT ())) {
@@ -8770,6 +8770,15 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
8770
8770
}
8771
8771
}
8772
8772
8773
+ // Some checks may be represented as inversion of simpler check, for example
8774
+ // "inf|normal|subnormal|zero" => !"nan".
8775
+ bool IsInverted = false ;
8776
+
8777
+ if (FPClassTest InvertedCheck = invertFPClassTestIfSimpler (Test, false )) {
8778
+ Test = InvertedCheck;
8779
+ IsInverted = true ;
8780
+ }
8781
+
8773
8782
// In the general case use integer operations.
8774
8783
unsigned BitSize = OperandVT.getScalarSizeInBits ();
8775
8784
EVT IntVT = EVT::getIntegerVT (*DAG.getContext (), BitSize);
0 commit comments