@@ -8675,7 +8675,7 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
8675
8675
// Degenerated cases.
8676
8676
if (Test == fcNone)
8677
8677
return DAG.getBoolConstant (false , DL, ResultVT, OperandVT);
8678
- if (( Test & fcAllFlags) == fcAllFlags)
8678
+ if (Test == fcAllFlags)
8679
8679
return DAG.getBoolConstant (true , DL, ResultVT, OperandVT);
8680
8680
8681
8681
// 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,
8686
8686
OperandVT = MVT::f64 ;
8687
8687
}
8688
8688
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
-
8697
8689
// Floating-point type properties.
8698
8690
EVT ScalarFloatVT = OperandVT.getScalarType ();
8699
8691
const Type *FloatTy = ScalarFloatVT.getTypeForEVT (*DAG.getContext ());
@@ -8705,9 +8697,16 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
8705
8697
if (Flags.hasNoFPExcept () &&
8706
8698
isOperationLegalOrCustom (ISD::SETCC, OperandVT.getScalarType ())) {
8707
8699
FPClassTest FPTestMask = Test;
8700
+ bool IsInvertedFP = false ;
8701
+
8702
+ if (FPClassTest InvertedFPCheck =
8703
+ invertFPClassTestIfSimpler (FPTestMask, true )) {
8704
+ FPTestMask = InvertedFPCheck;
8705
+ IsInvertedFP = true ;
8706
+ }
8708
8707
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;
8711
8710
8712
8711
// See if we can fold an | fcNan into an unordered compare.
8713
8712
FPClassTest OrderedFPTestMask = FPTestMask & ~fcNan;
@@ -8720,7 +8719,7 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
8720
8719
const bool IsOrdered = FPTestMask == OrderedFPTestMask;
8721
8720
8722
8721
if (std::optional<bool > IsCmp0 =
8723
- isFCmpEqualZero (Test , Semantics, DAG.getMachineFunction ());
8722
+ isFCmpEqualZero (FPTestMask , Semantics, DAG.getMachineFunction ());
8724
8723
IsCmp0 && (isCondCodeLegalOrCustom (
8725
8724
*IsCmp0 ? OrderedCmpOpcode : UnorderedCmpOpcode,
8726
8725
OperandVT.getScalarType ().getSimpleVT ()))) {
@@ -8732,31 +8731,35 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
8732
8731
*IsCmp0 ? OrderedCmpOpcode : UnorderedCmpOpcode);
8733
8732
}
8734
8733
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 ()))
8738
8737
return DAG.getSetCC (DL, ResultVT, Op, Op,
8739
- IsInverted ? ISD::SETO : ISD::SETUO);
8740
- }
8738
+ IsInvertedFP ? ISD::SETO : ISD::SETUO);
8741
8739
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,
8744
8744
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)))) {
8746
8749
// isinf(x) --> fabs(x) == inf
8747
8750
SDValue Abs = DAG.getNode (ISD::FABS, DL, OperandVT, Op);
8748
8751
SDValue Inf =
8749
8752
DAG.getConstantFP (APFloat::getInf (Semantics), DL, OperandVT);
8750
8753
return DAG.getSetCC (DL, ResultVT, Abs, Inf,
8751
- IsInverted ? ISD::SETUNE : ISD::SETOEQ );
8754
+ IsOrderedInf ? OrderedCmpOpcode : UnorderedCmpOpcode );
8752
8755
}
8753
8756
8754
8757
if (OrderedFPTestMask == (fcSubnormal | fcZero) && !IsOrdered) {
8755
8758
// TODO: Could handle ordered case, but it produces worse code for
8756
8759
// x86. Maybe handle ordered if fabs is free?
8757
8760
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;
8760
8763
8761
8764
if (isCondCodeLegalOrCustom (IsOrdered ? OrderedOp : UnorderedOp,
8762
8765
OperandVT.getScalarType ().getSimpleVT ())) {
@@ -8773,6 +8776,15 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
8773
8776
}
8774
8777
}
8775
8778
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
+
8776
8788
// In the general case use integer operations.
8777
8789
unsigned BitSize = OperandVT.getScalarSizeInBits ();
8778
8790
EVT IntVT = EVT::getIntegerVT (*DAG.getContext (), BitSize);
0 commit comments