-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[RISCV] Handle fixed length vectors with exact VLEN in loweringEXTRACT_SUBVECTOR #79949
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
Merged
Merged
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 |
---|---|---|
|
@@ -9616,12 +9616,15 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op, | |
if (OrigIdx == 0) | ||
return Op; | ||
|
||
// If the subvector vector is a fixed-length type, we cannot use subregister | ||
// manipulation to simplify the codegen; we don't know which register of a | ||
// LMUL group contains the specific subvector as we only know the minimum | ||
// register size. Therefore we must slide the vector group down the full | ||
// amount. | ||
if (SubVecVT.isFixedLengthVector()) { | ||
const unsigned MinVLen = Subtarget.getRealMinVLen(); | ||
const unsigned MaxVLen = Subtarget.getRealMaxVLen(); | ||
|
||
// If the subvector vector is a fixed-length type and we don't know VLEN | ||
// exactly, we cannot use subregister manipulation to simplify the codegen; we | ||
// don't know which register of a LMUL group contains the specific subvector | ||
// as we only know the minimum register size. Therefore we must slide the | ||
// vector group down the full amount. | ||
if (SubVecVT.isFixedLengthVector() && MinVLen != MaxVLen) { | ||
MVT ContainerVT = VecVT; | ||
if (VecVT.isFixedLengthVector()) { | ||
ContainerVT = getContainerForFixedLengthVector(VecVT); | ||
|
@@ -9653,19 +9656,47 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op, | |
return DAG.getBitcast(Op.getValueType(), Slidedown); | ||
} | ||
|
||
if (VecVT.isFixedLengthVector()) { | ||
VecVT = getContainerForFixedLengthVector(VecVT); | ||
Vec = convertToScalableVector(VecVT, Vec, DAG, Subtarget); | ||
} | ||
|
||
MVT ContainerSubVecVT = SubVecVT; | ||
if (SubVecVT.isFixedLengthVector()) | ||
ContainerSubVecVT = getContainerForFixedLengthVector(SubVecVT); | ||
|
||
unsigned SubRegIdx, RemIdx; | ||
std::tie(SubRegIdx, RemIdx) = | ||
RISCVTargetLowering::decomposeSubvectorInsertExtractToSubRegs( | ||
VecVT, SubVecVT, OrigIdx, TRI); | ||
// extract_subvector scales the index by vscale is the subvector is scalable, | ||
// and decomposeSubvectorInsertExtractToSubRegs takes this into account. So if | ||
// we have a fixed length subvector, we need to adjust the index by 1/vscale. | ||
if (SubVecVT.isFixedLengthVector()) { | ||
assert(MinVLen == MaxVLen); | ||
unsigned Vscale = MinVLen / RISCV::RVVBitsPerBlock; | ||
std::tie(SubRegIdx, RemIdx) = | ||
RISCVTargetLowering::decomposeSubvectorInsertExtractToSubRegs( | ||
VecVT, ContainerSubVecVT, OrigIdx / Vscale, TRI); | ||
RemIdx = (RemIdx * Vscale) + (OrigIdx % Vscale); | ||
} else { | ||
std::tie(SubRegIdx, RemIdx) = | ||
RISCVTargetLowering::decomposeSubvectorInsertExtractToSubRegs( | ||
VecVT, ContainerSubVecVT, OrigIdx, TRI); | ||
} | ||
|
||
// If the Idx has been completely eliminated then this is a subvector extract | ||
// which naturally aligns to a vector register. These can easily be handled | ||
// using subregister manipulation. | ||
if (RemIdx == 0) | ||
if (RemIdx == 0) { | ||
if (SubVecVT.isFixedLengthVector()) { | ||
Vec = DAG.getTargetExtractSubreg(SubRegIdx, DL, ContainerSubVecVT, Vec); | ||
return convertFromScalableVector(SubVecVT, Vec, DAG, Subtarget); | ||
} | ||
return Op; | ||
} | ||
|
||
// Else SubVecVT is a fractional LMUL and may need to be slid down. | ||
assert(RISCVVType::decodeVLMUL(getLMUL(SubVecVT)).second); | ||
// Else SubVecVT is a fractional LMUL and may need to be slid down: if | ||
// SubVecVT was > M1 then the index would need to be a multiple of VLMAX, and | ||
// so would divide exactly. | ||
assert(RISCVVType::decodeVLMUL(getLMUL(ContainerSubVecVT)).second); | ||
|
||
// If the vector type is an LMUL-group type, extract a subvector equal to the | ||
// nearest full vector register type. | ||
preames marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -9680,10 +9711,17 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op, | |
|
||
// Slide this vector register down by the desired number of elements in order | ||
// to place the desired subvector starting at element 0. | ||
SDValue SlidedownAmt = | ||
DAG.getVScale(DL, XLenVT, APInt(XLenVT.getSizeInBits(), RemIdx)); | ||
SDValue SlidedownAmt; | ||
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. As a follow up, I think there's room to simplify this via TypeSize and the IRBuilder routines for the same. We could express RemIdx as a TypeSize quantity, and abstract over the scalable vs fixed aspect of it. This is minor, and definitely worthy of it's own review. |
||
if (SubVecVT.isFixedLengthVector()) | ||
SlidedownAmt = DAG.getConstant(RemIdx, DL, Subtarget.getXLenVT()); | ||
else | ||
SlidedownAmt = | ||
DAG.getVScale(DL, XLenVT, APInt(XLenVT.getSizeInBits(), RemIdx)); | ||
|
||
auto [Mask, VL] = getDefaultScalableVLOps(InterSubVT, DL, DAG, Subtarget); | ||
if (SubVecVT.isFixedLengthVector()) | ||
VL = getVLOp(SubVecVT.getVectorNumElements(), InterSubVT, DL, DAG, | ||
Subtarget); | ||
SDValue Slidedown = | ||
getVSlidedown(DAG, Subtarget, DL, InterSubVT, DAG.getUNDEF(InterSubVT), | ||
Vec, SlidedownAmt, Mask, VL); | ||
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.