-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[X86] Lower mathlib call ldexp into scalef when avx512 is enabled #166839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KavinTheG
wants to merge
3
commits into
llvm:main
Choose a base branch
from
KavinTheG:x86_lower_ldexp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+379
−1,743
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1829,6 +1829,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM, | |
| setOperationAction(ISD::FCOPYSIGN, VT, Custom); | ||
| setOperationAction(ISD::FCANONICALIZE, VT, Custom); | ||
| } | ||
|
|
||
| setOperationAction(ISD::LRINT, MVT::v16f32, | ||
| Subtarget.hasDQI() ? Legal : Custom); | ||
| setOperationAction(ISD::LRINT, MVT::v8f64, | ||
|
|
@@ -2101,6 +2102,11 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM, | |
| // These operations are handled on non-VLX by artificially widening in | ||
| // isel patterns. | ||
|
|
||
| for (MVT VT : {MVT::f16, MVT::f32, MVT::f64, MVT::v8f16, MVT::v4f32, | ||
| MVT::v2f64, MVT::v16f16, MVT::v8f32, MVT::v4f64, MVT::v32f16, | ||
| MVT::v16f32, MVT::v8f64}) | ||
| setOperationAction(ISD::FLDEXP, VT, Custom); | ||
|
|
||
| setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::v8i32, Custom); | ||
| setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::v4i32, Custom); | ||
| setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::v2i32, Custom); | ||
|
|
@@ -19149,6 +19155,115 @@ 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); | ||
|
|
||
| switch (XTy.SimpleTy) { | ||
| default: | ||
| return SDValue(); | ||
| case MVT::f16: | ||
| if (!Subtarget.hasFP16()) { | ||
| X = DAG.getNode(ISD::FP_EXTEND, DL, MVT::f32, X); | ||
| } | ||
| break; | ||
| case MVT::f32: | ||
| case MVT::f64: | ||
| break; | ||
| case MVT::v4f32: | ||
| case MVT::v2f64: | ||
| if (Subtarget.hasVLX()) { | ||
| Exp = DAG.getNode(ISD::SINT_TO_FP, DL, XTy, Exp); | ||
| return DAG.getNode(X86ISD::SCALEFS, DL, XTy, X, Exp, X); | ||
| } | ||
| Exp = DAG.getNode(ISD::SINT_TO_FP, DL, X.getValueType(), Exp); | ||
| break; | ||
| case MVT::v8f16: | ||
| if (Subtarget.hasFP16()) { | ||
| if (Subtarget.hasVLX()) { | ||
| Exp = DAG.getNode(ISD::SINT_TO_FP, DL, XTy, Exp); | ||
| return DAG.getNode(X86ISD::SCALEF, DL, XTy, X, Exp, X); | ||
| } | ||
| break; | ||
| } | ||
| X = DAG.getNode(ISD::FP_EXTEND, DL, MVT::v8f32, X); | ||
| Exp = DAG.getNode(ISD::SIGN_EXTEND, DL, MVT::v8i32, Exp); | ||
| break; | ||
| case MVT::v8f32: | ||
| case MVT::v4f64: | ||
| if (Subtarget.hasVLX()) { | ||
| 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); | ||
| break; | ||
| case MVT::v16f16: | ||
| if (Subtarget.hasFP16()) { | ||
| if (Subtarget.hasVLX()) { | ||
| Exp = DAG.getNode(ISD::SINT_TO_FP, DL, XTy, Exp); | ||
| return DAG.getNode(X86ISD::SCALEF, DL, XTy, X, Exp, X); | ||
| } | ||
| break; | ||
| } | ||
| X = DAG.getNode(ISD::FP_EXTEND, DL, MVT::v16f32, X); | ||
| Exp = DAG.getNode(ISD::SIGN_EXTEND, DL, MVT::v16i32, Exp); | ||
| break; | ||
| 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); | ||
| case MVT::v32f16: | ||
| if (Subtarget.hasFP16()) { | ||
| Exp = DAG.getNode(ISD::SINT_TO_FP, DL, XTy, Exp); | ||
| return DAG.getNode(X86ISD::SCALEF, DL, XTy, X, Exp, X); | ||
| } | ||
| SDValue Low = DAG.getExtractSubvector(DL, MVT::v16f16, X, 0); | ||
| SDValue High = DAG.getExtractSubvector(DL, MVT::v16f16, X, 16); | ||
| SDValue ExpLow = DAG.getExtractSubvector(DL, MVT::v16i16, Exp, 0); | ||
| SDValue ExpHigh = DAG.getExtractSubvector(DL, MVT::v16i16, Exp, 16); | ||
|
|
||
| SDValue OpLow = DAG.getNode(ISD::FLDEXP, DL, MVT::v16f16, Low, ExpLow); | ||
| SDValue OpHigh = DAG.getNode(ISD::FLDEXP, DL, MVT::v16f16, High, ExpHigh); | ||
| SDValue ScaledLow = LowerFLDEXP(OpLow, Subtarget, DAG); | ||
| SDValue ScaledHigh = LowerFLDEXP(OpHigh, Subtarget, DAG); | ||
| return DAG.getNode(ISD::CONCAT_VECTORS, DL, MVT::v32f16, ScaledLow, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might be able to use splitVectorOp here? |
||
| ScaledHigh); | ||
| } | ||
|
|
||
| if (XTy.isVector()) { | ||
| SDValue WideX = widenSubVector(X, true, Subtarget, DAG, DL, 512); | ||
| SDValue WideExp = widenSubVector(Exp, true, Subtarget, DAG, DL, 512); | ||
| if (XTy.getScalarType() == MVT::f16 && !Subtarget.hasFP16()) { | ||
| WideExp = | ||
| DAG.getNode(ISD::SINT_TO_FP, DL, WideX.getSimpleValueType(), WideExp); | ||
| SDValue Scalef = DAG.getNode(X86ISD::SCALEF, DL, WideX.getValueType(), | ||
| WideX, WideExp, WideX); | ||
| MVT ExtractVT = XTy == MVT::v8f16 ? MVT::v8f32 : MVT::v16f32; | ||
| SDValue LowHalf = DAG.getExtractSubvector(DL, ExtractVT, Scalef, 0); | ||
| return DAG.getNode(ISD::FP_ROUND, DL, XTy, LowHalf, | ||
| DAG.getTargetConstant(0, DL, MVT::i32)); | ||
| } | ||
| SDValue Scalef = DAG.getNode(X86ISD::SCALEF, DL, WideX.getValueType(), | ||
| WideX, WideExp, WideX); | ||
| return DAG.getExtractSubvector(DL, XTy, Scalef, 0); | ||
| } else { | ||
| MVT VT = MVT::getVectorVT(X.getSimpleValueType(), | ||
| 128 / X.getSimpleValueType().getSizeInBits()); | ||
| Exp = DAG.getNode(ISD::SINT_TO_FP, DL, X.getValueType(), Exp); | ||
| SDValue VX = DAG.getInsertVectorElt(DL, DAG.getUNDEF(VT), X, 0); | ||
| SDValue VExp = DAG.getInsertVectorElt(DL, DAG.getUNDEF(VT), Exp, 0); | ||
| SDValue Scalefs = DAG.getNode(X86ISD::SCALEFS, DL, VT, VX, VExp, VX); | ||
| SDValue Final = DAG.getExtractVectorElt(DL, X.getValueType(), Scalefs, 0); | ||
| if (X.getValueType() != XTy) | ||
| Final = DAG.getNode(ISD::FP_ROUND, DL, XTy, Final, | ||
| DAG.getTargetConstant(0, DL, MVT::i32)); | ||
| return Final; | ||
| } | ||
| } | ||
|
|
||
| static SDValue LowerSCALAR_TO_VECTOR(SDValue Op, const X86Subtarget &Subtarget, | ||
| SelectionDAG &DAG) { | ||
| SDLoc dl(Op); | ||
|
|
@@ -33681,7 +33796,8 @@ SDValue X86TargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { | |
| case ISD::ADDRSPACECAST: return LowerADDRSPACECAST(Op, DAG); | ||
| case X86ISD::CVTPS2PH: return LowerCVTPS2PH(Op, DAG); | ||
| case ISD::PREFETCH: return LowerPREFETCH(Op, Subtarget, DAG); | ||
| // clang-format on | ||
| case ISD::FLDEXP: return LowerFLDEXP(Op, Subtarget, DAG); | ||
| // clang-format on | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why SCALEFS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mistake on my part, should be SCALEF.