Skip to content

Commit 66c7ffb

Browse files
committed
optimize is_finite on floating points
1 parent 2936852 commit 66c7ffb

File tree

10 files changed

+1220
-400
lines changed

10 files changed

+1220
-400
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9122,8 +9122,15 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
91229122
; // Detect finite numbers of f80 by checking individual classes because
91239123
// they have different settings of the explicit integer bit.
91249124
else if ((Test & fcFinite) == fcFinite) {
9125-
// finite(V) ==> abs(V) < exp_mask
9126-
PartialRes = DAG.getSetCC(DL, ResultVT, AbsV, ExpMaskV, ISD::SETLT);
9125+
// finite(V) ==> (a << 1) < (inf << 1)
9126+
//
9127+
// See https://github.com/llvm/llvm-project/issues/169270, this is slightly
9128+
// shorter than the `finite(V) ==> abs(V) < exp_mask` formula used before.
9129+
SDValue One = DAG.getShiftAmountConstant(1, IntVT, DL);
9130+
SDValue TwiceOp = DAG.getNode(ISD::SHL, DL, IntVT, OpAsInt, One);
9131+
SDValue TwiceInf = DAG.getNode(ISD::SHL, DL, IntVT, ExpMaskV, One);
9132+
9133+
PartialRes = DAG.getSetCC(DL, ResultVT, TwiceOp, TwiceInf, ISD::SETULT);
91279134
Test &= ~fcFinite;
91289135
} else if ((Test & fcFinite) == fcPosFinite) {
91299136
// finite(V) && V > 0 ==> V < exp_mask

0 commit comments

Comments
 (0)