[X86] use vdivph for i8 integer division on avx512fp16 - #215131
[X86] use vdivph for i8 integer division on avx512fp16#215131AryanBhirud wants to merge 1 commit into
Conversation
|
Hello @AryanBhirud 👋 Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.
Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description. Frequently asked questionsHow do I add reviewers? This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically. You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using What if there are no comments? If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers. Are any special GitHub settings required to contribute to LLVM? We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details. If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse. Thank you, |
|
@llvm/pr-subscribers-backend-x86 Author: Aryan Bhirud (AryanBhirud) ChangesCloses #214431 This patch enables lowering of i8 vector integer divisions through FP16 vector division when the target has fast vector FP16 division support. For i8 vector divisions, the existing lowering path can require widening through larger integer types before converting to floating point, introducing unnecessary conversions and preventing generation of the native vdivph instruction available on AVX512FP16 targets. This change:
Full diff: https://github.com/llvm/llvm-project/pull/215131.diff 2 Files Affected:
diff --git a/llvm/lib/Target/X86/X86.td b/llvm/lib/Target/X86/X86.td
index f40b937efa74b..299950c061356 100644
--- a/llvm/lib/Target/X86/X86.td
+++ b/llvm/lib/Target/X86/X86.td
@@ -798,6 +798,10 @@ def TuningFastDPWSSD
"Prefer vpdpwssd instruction over vpmaddwd+vpaddd instruction sequence",
[], InlineIgnore>;
+def TuningFastVectorFP16Div
+ : SubtargetFeature<"fast-vector-fp16-div", "HasFastFP16Div", "true",
+ "Vector FP16 division is fast",
+ [], InlineIgnore>;
def TuningPreferNoGather
: SubtargetFeature<"prefer-no-gather", "PreferGather", "false",
"Prefer no gather instructions",
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index c74d342fed1cb..d12b14861bb56 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -50669,7 +50669,10 @@ static SDValue combineIntDivRem(SDNode *N, SelectionDAG &DAG,
// f32 recovers the quotient exactly when both operands fit in 24 bits
MVT FPSclVT = MVT::f64;
- if (EltBits <= 16 || BothFitFP(APFloat::IEEEsingle()))
+ if (EltBits == 8 && Subtarget.hasFastFP16Div() &&
+ BothFitFP(APFloat::IEEEhalf()))
+ FPSclVT = MVT::f16;
+ else if (EltBits <= 16 || BothFitFP(APFloat::IEEEsingle()))
FPSclVT = MVT::f32;
EVT FPVT = VT.changeVectorElementType(*DAG.getContext(), FPSclVT);
@@ -50728,8 +50731,15 @@ static SDValue combineIntDivRem(SDNode *N, SelectionDAG &DAG,
Q = IsSigned ? DAG.getSExtOrTrunc(Q, DL, VT)
: DAG.getZExtOrTrunc(Q, DL, VT);
} else {
+ SDValue FPQuot = DAG.getNode(ISD::FDIV, DL, FPVT, X, Y);
unsigned FromFP = IsSigned ? ISD::FP_TO_SINT : ISD::FP_TO_UINT;
- Q = DAG.getNode(FromFP, DL, VT, DAG.getNode(ISD::FDIV, DL, FPVT, X, Y));
+ if (FPSclVT == MVT::f16 && EltBits == 8) {
+ EVT I16VT = VT.changeVectorElementType(*DAG.getContext(), MVT::i16);
+ SDValue Q16 = DAG.getNode(FromFP, DL, I16VT, FPQuot);
+ Q = DAG.getNode(ISD::TRUNCATE, DL, VT, Q16);
+ } else {
+ Q = DAG.getNode(FromFP, DL, VT, FPQuot);
+ }
}
if (!IsRem)
return Q;
|
| // f32 recovers the quotient exactly when both operands fit in 24 bits | ||
| MVT FPSclVT = MVT::f64; | ||
| if (EltBits <= 16 || BothFitFP(APFloat::IEEEsingle())) | ||
| if (EltBits == 8 && Subtarget.hasFastFP16Div() && |
There was a problem hiding this comment.
(EltBits == 8 || BothFitFP(APFloat::IEEEhalf())) && Subtarget.hasFastFP16Div()
|
test coverage? |
Closes #214431
This patch enables lowering of i8 vector integer divisions through FP16 vector division when the target has fast vector FP16 division support.
For i8 vector divisions, the existing lowering path can require widening through larger integer types before converting to floating point, introducing unnecessary conversions and preventing generation of the native vdivph instruction available on AVX512FP16 targets.
This change: