@@ -3650,6 +3650,27 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
3650
3650
// FIXME: Use separate LibCall action.
3651
3651
if (TLI.getLibcallName (LC))
3652
3652
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
+ }
3653
3674
3654
3675
if (SDValue Expanded = expandLdexp (Node)) {
3655
3676
Results.push_back (Expanded);
0 commit comments