-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[DAG][RISCV] Use vp_reduce_* when widening illegal types for reductions #105455
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8d6c803
[DAG][RISCV] Use vp_reduce_* when widening illegal types for reductions
preames d2cac62
clang-format
preames 36ae990
Add support for unordered FP types and a bit of code style cleanup
preames 41dcac0
Merge branch 'main' into pr-riscv-reduce-widen-via-vp
preames 7a7455f
Update comments
preames 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 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
This file contains 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 |
---|---|---|
|
@@ -7259,9 +7259,38 @@ SDValue DAGTypeLegalizer::WidenVecOp_STRICT_FSETCC(SDNode *N) { | |
return DAG.getBuildVector(VT, dl, Scalars); | ||
} | ||
|
||
static unsigned getExtendForIntVecReduction(SDNode *N) { | ||
switch (N->getOpcode()) { | ||
default: | ||
llvm_unreachable("Expected integer vector reduction"); | ||
case ISD::VECREDUCE_ADD: | ||
case ISD::VECREDUCE_MUL: | ||
case ISD::VECREDUCE_AND: | ||
case ISD::VECREDUCE_OR: | ||
case ISD::VECREDUCE_XOR: | ||
case ISD::VP_REDUCE_ADD: | ||
case ISD::VP_REDUCE_MUL: | ||
case ISD::VP_REDUCE_AND: | ||
case ISD::VP_REDUCE_OR: | ||
case ISD::VP_REDUCE_XOR: | ||
return ISD::ANY_EXTEND; | ||
case ISD::VECREDUCE_SMAX: | ||
case ISD::VECREDUCE_SMIN: | ||
case ISD::VP_REDUCE_SMAX: | ||
case ISD::VP_REDUCE_SMIN: | ||
return ISD::SIGN_EXTEND; | ||
case ISD::VECREDUCE_UMAX: | ||
case ISD::VECREDUCE_UMIN: | ||
case ISD::VP_REDUCE_UMAX: | ||
case ISD::VP_REDUCE_UMIN: | ||
return ISD::ZERO_EXTEND; | ||
} | ||
} | ||
|
||
SDValue DAGTypeLegalizer::WidenVecOp_VECREDUCE(SDNode *N) { | ||
SDLoc dl(N); | ||
SDValue Op = GetWidenedVector(N->getOperand(0)); | ||
EVT VT = N->getValueType(0); | ||
EVT OrigVT = N->getOperand(0).getValueType(); | ||
EVT WideVT = Op.getValueType(); | ||
EVT ElemVT = OrigVT.getVectorElementType(); | ||
|
@@ -7276,6 +7305,25 @@ SDValue DAGTypeLegalizer::WidenVecOp_VECREDUCE(SDNode *N) { | |
unsigned OrigElts = OrigVT.getVectorMinNumElements(); | ||
unsigned WideElts = WideVT.getVectorMinNumElements(); | ||
|
||
// Generate a vp.reduce_op if it is custom/legal for the target. This avoids | ||
// need pad the source vector, because the inactive lanes can simply be | ||
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. the need to pad? |
||
// disabled and not contribute to the result. To avoid possible recursion, | ||
// only do this if the widened mask type is legal. | ||
if (auto VPOpcode = ISD::getVPForBaseOpcode(Opc); | ||
VPOpcode && VT.isInteger() && | ||
TLI.isOperationLegalOrCustom(*VPOpcode, WideVT)) { | ||
if (EVT WideMaskVT = EVT::getVectorVT(*DAG.getContext(), MVT::i1, | ||
WideVT.getVectorElementCount()); | ||
TLI.isTypeLegal(WideMaskVT)) { | ||
SDValue Start = | ||
DAG.getNode(getExtendForIntVecReduction(N), dl, VT, NeutralElem); | ||
SDValue Mask = DAG.getAllOnesConstant(dl, WideMaskVT); | ||
SDValue EVL = DAG.getElementCount(dl, TLI.getVPExplicitVectorLengthTy(), | ||
OrigVT.getVectorElementCount()); | ||
return DAG.getNode(*VPOpcode, dl, VT, {Start, Op, Mask, EVL}, Flags); | ||
} | ||
} | ||
|
||
if (WideVT.isScalableVector()) { | ||
unsigned GCD = std::gcd(OrigElts, WideElts); | ||
EVT SplatVT = EVT::getVectorVT(*DAG.getContext(), ElemVT, | ||
|
@@ -7284,14 +7332,14 @@ SDValue DAGTypeLegalizer::WidenVecOp_VECREDUCE(SDNode *N) { | |
for (unsigned Idx = OrigElts; Idx < WideElts; Idx = Idx + GCD) | ||
Op = DAG.getNode(ISD::INSERT_SUBVECTOR, dl, WideVT, Op, SplatNeutral, | ||
DAG.getVectorIdxConstant(Idx, dl)); | ||
return DAG.getNode(Opc, dl, N->getValueType(0), Op, Flags); | ||
return DAG.getNode(Opc, dl, VT, Op, Flags); | ||
} | ||
|
||
for (unsigned Idx = OrigElts; Idx < WideElts; Idx++) | ||
Op = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, WideVT, Op, NeutralElem, | ||
DAG.getVectorIdxConstant(Idx, dl)); | ||
|
||
return DAG.getNode(Opc, dl, N->getValueType(0), Op, Flags); | ||
return DAG.getNode(Opc, dl, VT, Op, Flags); | ||
} | ||
|
||
SDValue DAGTypeLegalizer::WidenVecOp_VECREDUCE_SEQ(SDNode *N) { | ||
|
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.
Is this the same as getExtendForIntVecReduction in LegalizeIntegerTypes.cpp? If so is there a way to deduplicate it