Skip to content

Commit d51a155

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 226d977 commit d51a155

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
@@ -8790,6 +8790,31 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
87908790
IsOrdered ? OrderedOp : UnorderedOp);
87918791
}
87928792
}
8793+
8794+
if (FPTestMask == fcNormal) {
8795+
// TODO: Handle unordered
8796+
ISD::CondCode IsFiniteOp = IsInvertedFP ? ISD::SETUGE : ISD::SETOLT;
8797+
ISD::CondCode IsNormalOp = IsInvertedFP ? ISD::SETOLT : ISD::SETUGE;
8798+
8799+
if (isCondCodeLegalOrCustom(IsFiniteOp,
8800+
OperandVT.getScalarType().getSimpleVT()) &&
8801+
isCondCodeLegalOrCustom(IsNormalOp,
8802+
OperandVT.getScalarType().getSimpleVT()) &&
8803+
isFAbsFree(OperandVT)) {
8804+
// isnormal(x) --> fabs(x) < infinity && !(fabs(x) < smallest_normal)
8805+
SDValue Inf =
8806+
DAG.getConstantFP(APFloat::getInf(Semantics), DL, OperandVT);
8807+
SDValue SmallestNormal = DAG.getConstantFP(
8808+
APFloat::getSmallestNormalized(Semantics), DL, OperandVT);
8809+
8810+
SDValue Abs = DAG.getNode(ISD::FABS, DL, OperandVT, Op);
8811+
SDValue IsFinite = DAG.getSetCC(DL, ResultVT, Abs, Inf, IsFiniteOp);
8812+
SDValue IsNormal =
8813+
DAG.getSetCC(DL, ResultVT, Abs, SmallestNormal, IsNormalOp);
8814+
unsigned LogicOp = IsInvertedFP ? ISD::OR : ISD::AND;
8815+
return DAG.getNode(LogicOp, DL, ResultVT, IsFinite, IsNormal);
8816+
}
8817+
}
87938818
}
87948819

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

0 commit comments

Comments
 (0)