[llvm] [X86] Lower mathlib call ldexp into scalef when avx512 is enabled (PR #166839)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 10 02:29:35 PST 2025


================
@@ -19142,6 +19152,75 @@ SDValue X86TargetLowering::LowerINSERT_VECTOR_ELT(SDValue Op,
   return SDValue();
 }
 
+static SDValue LowerFLDEXP(SDValue Op, const X86Subtarget &Subtarget,
+                           SelectionDAG &DAG) {
+  SDLoc DL(Op);
+  SDValue X = Op.getOperand(0);
+  MVT XTy = X.getSimpleValueType();
+  SDValue Exp = Op.getOperand(1);
+  MVT XVT, ExpVT;
+
+  switch (XTy.SimpleTy) {
+  default:
+    return SDValue();
+  case MVT::f16:
+    if (Subtarget.hasFP16()) {
+      XVT = MVT::v8f16;
+      ExpVT = XVT;
+      break;
+    }
+    X = DAG.getNode(ISD::FP_EXTEND, DL, MVT::f32, X);
+    [[fallthrough]];
+  case MVT::f32:
+    XVT = MVT::v4f32;
+    ExpVT = MVT::v4f32;
+    break;
+  case MVT::f64:
+    XVT = MVT::v2f64;
+    ExpVT = MVT::v2f64;
+    break;
+  case MVT::v4f32:
+  case MVT::v2f64:
+    if (!Subtarget.hasVLX()) {
+      XVT = XTy == MVT::v4f32 ? MVT::v16f32 : MVT::v8f64;
+      ExpVT = XVT;
+      break;
+    }
+    [[fallthrough]];
+  case MVT::v8f32:
+  case MVT::v4f64:
+    if (!Subtarget.hasVLX()) {
+      XVT = XTy == MVT::v8f32 ? MVT::v16f32 : MVT::v8f64;
+      ExpVT = XVT;
+      break;
+    }
+    [[fallthrough]];
+  case MVT::v16f32:
+  case MVT::v8f64:
+    Exp = DAG.getNode(ISD::SINT_TO_FP, DL, XTy, Exp);
+    return DAG.getNode(X86ISD::SCALEF, DL, XTy, X, Exp, X);
+  }
+
+  Exp = DAG.getNode(ISD::SINT_TO_FP, DL, X.getValueType(), Exp);
+  if (XTy.isVector()) {
+    SDValue WideX = DAG.getInsertSubvector(DL, DAG.getUNDEF(XVT), X, 0);
+    SDValue WideExp = DAG.getInsertSubvector(DL, DAG.getUNDEF(ExpVT), Exp, 0);
----------------
RKSimon wrote:

You should be able to just use widenSubVector and tell it to widen to 512-bits instead of recomputing XVT/ExptVT

https://github.com/llvm/llvm-project/pull/166839


More information about the llvm-commits mailing list