@@ -8652,6 +8652,31 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
86528652 return DAG.getSetCC (DL, ResultVT, Op, Inf,
86538653 IsOrdered ? OrderedCmpOpcode : UnorderedCmpOpcode);
86548654 }
8655+
8656+ if (FPTestMask == fcNormal) {
8657+ // TODO: Handle unordered
8658+ ISD::CondCode IsFiniteOp = IsInvertedFP ? ISD::SETUGE : ISD::SETOLT;
8659+ ISD::CondCode IsNormalOp = IsInvertedFP ? ISD::SETOLT : ISD::SETUGE;
8660+
8661+ if (isCondCodeLegalOrCustom (IsFiniteOp,
8662+ OperandVT.getScalarType ().getSimpleVT ()) &&
8663+ isCondCodeLegalOrCustom (IsNormalOp,
8664+ OperandVT.getScalarType ().getSimpleVT ()) &&
8665+ isFAbsFree (OperandVT)) {
8666+ // isnormal(x) --> fabs(x) < infinity && !(fabs(x) < smallest_normal)
8667+ SDValue Inf =
8668+ DAG.getConstantFP (APFloat::getInf (Semantics), DL, OperandVT);
8669+ SDValue SmallestNormal = DAG.getConstantFP (
8670+ APFloat::getSmallestNormalized (Semantics), DL, OperandVT);
8671+
8672+ SDValue Abs = DAG.getNode (ISD::FABS, DL, OperandVT, Op);
8673+ SDValue IsFinite = DAG.getSetCC (DL, ResultVT, Abs, Inf, IsFiniteOp);
8674+ SDValue IsNormal =
8675+ DAG.getSetCC (DL, ResultVT, Abs, SmallestNormal, IsNormalOp);
8676+ unsigned LogicOp = IsInvertedFP ? ISD::OR : ISD::AND;
8677+ return DAG.getNode (LogicOp, DL, ResultVT, IsFinite, IsNormal);
8678+ }
8679+ }
86558680 }
86568681
86578682 // Some checks may be represented as inversion of simpler check, for example
0 commit comments