Skip to content

Commit 032a5a6

Browse files
committed
[RISCV] Refactor extract_subvector slightly. NFC
This patch refactors extract_subvector to lower to extract_subreg directly, and to shortcut whenever the index is 0 when extracting a scalable vector. This doesn't change any of the existing behaviour, but makes an upcoming patch that extends the scalable path slightly easier to read.
1 parent 9bba3dd commit 032a5a6

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8622,17 +8622,18 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op,
86228622
return DAG.getSetCC(DL, SubVecVT, Vec, SplatZero, ISD::SETNE);
86238623
}
86248624
}
8625+
8626+
// With an index of 0 this is a cast-like subvector, which can be performed
8627+
// with subregister operations.
8628+
if (OrigIdx == 0)
8629+
return Op;
86258630

86268631
// If the subvector vector is a fixed-length type, we cannot use subregister
86278632
// manipulation to simplify the codegen; we don't know which register of a
86288633
// LMUL group contains the specific subvector as we only know the minimum
86298634
// register size. Therefore we must slide the vector group down the full
86308635
// amount.
86318636
if (SubVecVT.isFixedLengthVector()) {
8632-
// With an index of 0 this is a cast-like subvector, which can be performed
8633-
// with subregister operations.
8634-
if (OrigIdx == 0)
8635-
return Op;
86368637
MVT ContainerVT = VecVT;
86378638
if (VecVT.isFixedLengthVector()) {
86388639
ContainerVT = getContainerForFixedLengthVector(VecVT);
@@ -8664,17 +8665,15 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op,
86648665
if (RemIdx == 0)
86658666
return Op;
86668667

8667-
// Else we must shift our vector register directly to extract the subvector.
8668-
// Do this using VSLIDEDOWN.
8668+
// Else SubVecVT is a fractional LMUL and needs to be slid down.
8669+
assert(RISCVVType::decodeVLMUL(getLMUL(SubVecVT)).second);
86698670

86708671
// If the vector type is an LMUL-group type, extract a subvector equal to the
8671-
// nearest full vector register type. This should resolve to a EXTRACT_SUBREG
8672-
// instruction.
8672+
// nearest full vector register type.
86738673
MVT InterSubVT = VecVT;
86748674
if (VecVT.bitsGT(getLMUL1VT(VecVT))) {
86758675
InterSubVT = getLMUL1VT(VecVT);
8676-
Vec = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, InterSubVT, Vec,
8677-
DAG.getConstant(OrigIdx - RemIdx, DL, XLenVT));
8676+
Vec = DAG.getTargetExtractSubreg(SubRegIdx, DL, InterSubVT, Vec);
86788677
}
86798678

86808679
// Slide this vector register down by the desired number of elements in order

0 commit comments

Comments
 (0)