Skip to content

Commit fcfbc51

Browse files
committed
DAG: Lower fcNormal is.fpclass to compare with inf
Looks worse for x86 without the fabs check. Not sure if this is useful for any targets.
1 parent fc46244 commit fcfbc51

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8673,6 +8673,31 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
86738673
IsOrdered ? OrderedOp : UnorderedOp);
86748674
}
86758675
}
8676+
8677+
if (FPTestMask == fcNormal) {
8678+
// TODO: Handle unordered
8679+
ISD::CondCode IsFiniteOp = IsInvertedFP ? ISD::SETUGE : ISD::SETOLT;
8680+
ISD::CondCode IsNormalOp = IsInvertedFP ? ISD::SETOLT : ISD::SETUGE;
8681+
8682+
if (isCondCodeLegalOrCustom(IsFiniteOp,
8683+
OperandVT.getScalarType().getSimpleVT()) &&
8684+
isCondCodeLegalOrCustom(IsNormalOp,
8685+
OperandVT.getScalarType().getSimpleVT()) &&
8686+
isFAbsFree(OperandVT)) {
8687+
// isnormal(x) --> fabs(x) < infinity && !(fabs(x) < smallest_normal)
8688+
SDValue Inf =
8689+
DAG.getConstantFP(APFloat::getInf(Semantics), DL, OperandVT);
8690+
SDValue SmallestNormal = DAG.getConstantFP(
8691+
APFloat::getSmallestNormalized(Semantics), DL, OperandVT);
8692+
8693+
SDValue Abs = DAG.getNode(ISD::FABS, DL, OperandVT, Op);
8694+
SDValue IsFinite = DAG.getSetCC(DL, ResultVT, Abs, Inf, IsFiniteOp);
8695+
SDValue IsNormal =
8696+
DAG.getSetCC(DL, ResultVT, Abs, SmallestNormal, IsNormalOp);
8697+
unsigned LogicOp = IsInvertedFP ? ISD::OR : ISD::AND;
8698+
return DAG.getNode(LogicOp, DL, ResultVT, IsFinite, IsNormal);
8699+
}
8700+
}
86768701
}
86778702

86788703
// Some checks may be represented as inversion of simpler check, for example

0 commit comments

Comments
 (0)