[llvm] [TargetLowering] Lower ldexp into target supported instructions (PR #67552)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 7 18:35:57 PDT 2023


================
@@ -57389,3 +57396,40 @@ Align X86TargetLowering::getPrefLoopAlignment(MachineLoop *ML) const {
     return Align(1ULL << ExperimentalPrefInnermostLoopAlignment);
   return TargetLowering::getPrefLoopAlignment();
 }
+
+SDValue X86TargetLowering::LowerFLDEXP(SDValue Op, SelectionDAG &DAG) const {
+  SDValue X = Op.getOperand(0);
+  EVT XScalarTy = X.getValueType();
+  SDValue Exp = Op.getOperand(1);
+
+  SDLoc DL(Op);
+  EVT XVT, ExpVT;
+  SDValue IID;
+  switch (Op.getValueSizeInBits()) {
+  default:
+    return SDValue();
+  case 32:
+    XVT = MVT::v4f32;
+    ExpVT = MVT::v4f32;
+    IID = DAG.getConstant(Intrinsic::x86_avx512_mask_scalef_ss, DL, MVT::i64);
+    break;
+  case 64:
+    XVT = MVT::v2f64;
+    ExpVT = MVT::v2f64;
+    IID = DAG.getConstant(Intrinsic::x86_avx512_mask_scalef_sd, DL, MVT::i64);
+    break;
+  }
+
+  SDValue Zero = DAG.getConstant(0, DL, MVT::i64);
+  Exp = DAG.getNode(ISD::SINT_TO_FP, DL, XScalarTy, Exp);
+  SDValue VX =
+      DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, XVT, DAG.getUNDEF(XVT), X, Zero);
+  SDValue VExp = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, ExpVT,
----------------
huhu233 wrote:

Hi, @arsenm, here are some of may consideration:

* Is this lowering the scalar case as a vector operation?
Actually, `ldexp at PLT` (ISD::`FLDEXP`) is a scalar call, but `llvm.aarch64.sve.fscale.*` or `llvm.x86.mask.scalef.*` only has vector versions. I hope to replace call with more efficient target supported instructions, so there are some `INSERT_VECTOR_ELT` and `EXTRACT_VECTOR_ELT`. 

* "Should this move to the vector legalizer?" 
`FLDEXP` will occur in many scalar cases, so I think it is not necessary to move to the vector legalizer.

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


More information about the llvm-commits mailing list