Skip to content

Commit 4859ae6

Browse files
committed
optimize is_finite on floating points
1 parent 2936852 commit 4859ae6

File tree

10 files changed

+1222
-400
lines changed

10 files changed

+1222
-400
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9122,8 +9122,17 @@ 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 slightly
9128+
// shorter than the `finite(V) ==> abs(V) < exp_mask` formula used before.
9129+
EVT ShVT = getShiftAmountTy(IntVT, DAG.getDataLayout());
9130+
SDValue One = DAG.getConstant(1, DL, ShVT);
9131+
9132+
SDValue TwiceOp = DAG.getNode(ISD::SHL, DL, IntVT, OpAsInt, One);
9133+
SDValue TwiceInf = DAG.getNode(ISD::SHL, DL, IntVT, ExpMaskV, One);
9134+
9135+
PartialRes = DAG.getSetCC(DL, ResultVT, TwiceOp, TwiceInf, ISD::SETULT);
91279136
Test &= ~fcFinite;
91289137
} else if ((Test & fcFinite) == fcPosFinite) {
91299138
// finite(V) && V > 0 ==> V < exp_mask

0 commit comments

Comments
 (0)