Skip to content

Commit 067e8b8

Browse files
authored
DAG: Lower fcNormal is.fpclass to compare with inf (#100389)
1 parent f42785d commit 067e8b8

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
@@ -8817,6 +8817,31 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
88178817
IsOrdered ? OrderedOp : UnorderedOp);
88188818
}
88198819
}
8820+
8821+
if (FPTestMask == fcNormal) {
8822+
// TODO: Handle unordered
8823+
ISD::CondCode IsFiniteOp = IsInvertedFP ? ISD::SETUGE : ISD::SETOLT;
8824+
ISD::CondCode IsNormalOp = IsInvertedFP ? ISD::SETOLT : ISD::SETUGE;
8825+
8826+
if (isCondCodeLegalOrCustom(IsFiniteOp,
8827+
OperandVT.getScalarType().getSimpleVT()) &&
8828+
isCondCodeLegalOrCustom(IsNormalOp,
8829+
OperandVT.getScalarType().getSimpleVT()) &&
8830+
isFAbsFree(OperandVT)) {
8831+
// isnormal(x) --> fabs(x) < infinity && !(fabs(x) < smallest_normal)
8832+
SDValue Inf =
8833+
DAG.getConstantFP(APFloat::getInf(Semantics), DL, OperandVT);
8834+
SDValue SmallestNormal = DAG.getConstantFP(
8835+
APFloat::getSmallestNormalized(Semantics), DL, OperandVT);
8836+
8837+
SDValue Abs = DAG.getNode(ISD::FABS, DL, OperandVT, Op);
8838+
SDValue IsFinite = DAG.getSetCC(DL, ResultVT, Abs, Inf, IsFiniteOp);
8839+
SDValue IsNormal =
8840+
DAG.getSetCC(DL, ResultVT, Abs, SmallestNormal, IsNormalOp);
8841+
unsigned LogicOp = IsInvertedFP ? ISD::OR : ISD::AND;
8842+
return DAG.getNode(LogicOp, DL, ResultVT, IsFinite, IsNormal);
8843+
}
8844+
}
88208845
}
88218846

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

0 commit comments

Comments
 (0)