Skip to content

Commit 1f9ca89

Browse files
authored
[RISCV] Don't create insert/extract subreg during lowering. (#109754)
Create the equivalent INSERT_SUBVECTOR/EXTRACT_SUBVECTOR instead. When we tried porting this to global isel, we noticed that subreg operations are created early. We aren't able to do this until instruction selection in global isel. For SelectionDAG, it makes sense to use insert/extract_subvector as the canonical form for these operations pre-isel. If it had come into SelectionDAG as a insert/extract_subvector we would have kept it in that form.
1 parent 6c7134b commit 1f9ca89

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10299,8 +10299,12 @@ SDValue RISCVTargetLowering::lowerINSERT_SUBVECTOR(SDValue Op,
1029910299
return Op;
1030010300
}
1030110301

10302+
// Use a insert_subvector that will resolve to an insert subreg.
10303+
assert(VLen);
10304+
unsigned Vscale = *VLen / RISCV::RVVBitsPerBlock;
1030210305
SDValue Insert =
10303-
DAG.getTargetInsertSubreg(SubRegIdx, DL, ContainerVecVT, Vec, SubVec);
10306+
DAG.getNode(ISD::INSERT_SUBVECTOR, DL, ContainerVecVT, Vec, SubVec,
10307+
DAG.getConstant(OrigIdx / Vscale, DL, XLenVT));
1030410308
if (VecVT.isFixedLengthVector())
1030510309
Insert = convertFromScalableVector(VecVT, Insert, DAG, Subtarget);
1030610310
return Insert;
@@ -10316,8 +10320,10 @@ SDValue RISCVTargetLowering::lowerINSERT_SUBVECTOR(SDValue Op,
1031610320
MVT InterSubVT = ContainerVecVT;
1031710321
SDValue AlignedExtract = Vec;
1031810322
unsigned AlignedIdx = OrigIdx - RemIdx.getKnownMinValue();
10319-
if (SubVecVT.isFixedLengthVector())
10323+
if (SubVecVT.isFixedLengthVector()) {
10324+
assert(VLen);
1032010325
AlignedIdx /= *VLen / RISCV::RVVBitsPerBlock;
10326+
}
1032110327
if (ContainerVecVT.bitsGT(getLMUL1VT(ContainerVecVT))) {
1032210328
InterSubVT = getLMUL1VT(ContainerVecVT);
1032310329
// Extract a subvector equal to the nearest full vector register type. This
@@ -10494,10 +10500,14 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op,
1049410500

1049510501
// If the Idx has been completely eliminated then this is a subvector extract
1049610502
// which naturally aligns to a vector register. These can easily be handled
10497-
// using subregister manipulation.
10503+
// using subregister manipulation. We use an extract_subvector that will
10504+
// resolve to an extract subreg.
1049810505
if (RemIdx.isZero()) {
1049910506
if (SubVecVT.isFixedLengthVector()) {
10500-
Vec = DAG.getTargetExtractSubreg(SubRegIdx, DL, ContainerSubVecVT, Vec);
10507+
assert(VLen);
10508+
unsigned Vscale = *VLen / RISCV::RVVBitsPerBlock;
10509+
Vec = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, ContainerSubVecVT, Vec,
10510+
DAG.getConstant(OrigIdx / Vscale, DL, XLenVT));
1050110511
return convertFromScalableVector(SubVecVT, Vec, DAG, Subtarget);
1050210512
}
1050310513
return Op;
@@ -10515,9 +10525,16 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op,
1051510525
if (VecVT.bitsGT(getLMUL1VT(VecVT))) {
1051610526
// If VecVT has an LMUL > 1, then SubVecVT should have a smaller LMUL, and
1051710527
// we should have successfully decomposed the extract into a subregister.
10528+
// We use an extract_subvector that will resolve to a subreg extract.
1051810529
assert(SubRegIdx != RISCV::NoSubRegister);
10530+
unsigned Idx = OrigIdx - RemIdx.getKnownMinValue();
10531+
if (SubVecVT.isFixedLengthVector()) {
10532+
assert(VLen);
10533+
Idx /= *VLen / RISCV::RVVBitsPerBlock;
10534+
}
1051910535
InterSubVT = getLMUL1VT(VecVT);
10520-
Vec = DAG.getTargetExtractSubreg(SubRegIdx, DL, InterSubVT, Vec);
10536+
Vec = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, InterSubVT, Vec,
10537+
DAG.getConstant(Idx, DL, XLenVT));
1052110538
}
1052210539

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

0 commit comments

Comments
 (0)