Skip to content

Commit c8faadb

Browse files
committed
[SelectionDAG] Lower llvm.ldexp.f32 to ldexp() on Windows.
This reduces codesize. As discussed in llvm#92707.
1 parent 5ae5774 commit c8faadb

File tree

2 files changed

+296
-594
lines changed

2 files changed

+296
-594
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3650,6 +3650,27 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
36503650
// FIXME: Use separate LibCall action.
36513651
if (TLI.getLibcallName(LC))
36523652
break;
3653+
if (Node->getOpcode() == ISD::FLDEXP && VT == MVT::f32 &&
3654+
TLI.isTypeLegal(MVT::f64) &&
3655+
TLI.getLibcallName(RTLIB::getLDEXP(MVT::f64))) {
3656+
// On Windows, it's common to be missing the 32-bit libcall, but have
3657+
// the 64-bit libcall. Expand to the 64-bit libcall. (Note that ldexp
3658+
// involves a rounding step if the result is subnormal, but that isn't
3659+
// relevant here because any subnormal result will round to zero when
3660+
// it's truncated.)
3661+
//
3662+
// FIXME: Consider doing something similar for f16/bf16. But be very
3663+
// careful handling bf16: expanding bf16->f64 is fine, but expanding
3664+
// bf16->f32 would produce incorrect subnormal results.
3665+
SDValue Extended =
3666+
DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Node->getOperand(0));
3667+
SDValue LdExp =
3668+
DAG.getNode(ISD::FLDEXP, dl, MVT::f64, Extended, Node->getOperand(1));
3669+
Results.push_back(
3670+
DAG.getNode(ISD::FP_ROUND, dl, VT, LdExp,
3671+
DAG.getIntPtrConstant(0, dl, /*isTarget=*/true)));
3672+
break;
3673+
}
36533674

36543675
if (SDValue Expanded = expandLdexp(Node)) {
36553676
Results.push_back(Expanded);

0 commit comments

Comments
 (0)