Skip to content

Commit b46d701

Browse files
authored
[RISCV] Refactor extract_subvector lowering slightly. NFC (#65391)
This patch refactors extract_subvector lowering 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 2618154 commit b46d701

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8735,16 +8735,17 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op,
87358735
}
87368736
}
87378737

8738+
// With an index of 0 this is a cast-like subvector, which can be performed
8739+
// with subregister operations.
8740+
if (OrigIdx == 0)
8741+
return Op;
8742+
87388743
// If the subvector vector is a fixed-length type, we cannot use subregister
87398744
// manipulation to simplify the codegen; we don't know which register of a
87408745
// LMUL group contains the specific subvector as we only know the minimum
87418746
// register size. Therefore we must slide the vector group down the full
87428747
// amount.
87438748
if (SubVecVT.isFixedLengthVector()) {
8744-
// With an index of 0 this is a cast-like subvector, which can be performed
8745-
// with subregister operations.
8746-
if (OrigIdx == 0)
8747-
return Op;
87488749
MVT ContainerVT = VecVT;
87498750
if (VecVT.isFixedLengthVector()) {
87508751
ContainerVT = getContainerForFixedLengthVector(VecVT);
@@ -8776,17 +8777,18 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op,
87768777
if (RemIdx == 0)
87778778
return Op;
87788779

8779-
// Else we must shift our vector register directly to extract the subvector.
8780-
// Do this using VSLIDEDOWN.
8780+
// Else SubVecVT is a fractional LMUL and may need to be slid down.
8781+
assert(RISCVVType::decodeVLMUL(getLMUL(SubVecVT)).second);
87818782

87828783
// If the vector type is an LMUL-group type, extract a subvector equal to the
8783-
// nearest full vector register type. This should resolve to a EXTRACT_SUBREG
8784-
// instruction.
8784+
// nearest full vector register type.
87858785
MVT InterSubVT = VecVT;
87868786
if (VecVT.bitsGT(getLMUL1VT(VecVT))) {
8787+
// If VecVT has an LMUL > 1, then SubVecVT should have a smaller LMUL, and
8788+
// we should have successfully decomposed the extract into a subregister.
8789+
assert(SubRegIdx != RISCV::NoSubRegister);
87878790
InterSubVT = getLMUL1VT(VecVT);
8788-
Vec = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, InterSubVT, Vec,
8789-
DAG.getConstant(OrigIdx - RemIdx, DL, XLenVT));
8791+
Vec = DAG.getTargetExtractSubreg(SubRegIdx, DL, InterSubVT, Vec);
87908792
}
87918793

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

0 commit comments

Comments
 (0)