[llvm] 1f9ca89 - [RISCV] Don't create insert/extract subreg during lowering. (#109754)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 24 15:54:52 PDT 2024
Author: Craig Topper
Date: 2024-09-24T15:54:49-07:00
New Revision: 1f9ca897987358053374b724444c2aa396e51032
URL: https://github.com/llvm/llvm-project/commit/1f9ca897987358053374b724444c2aa396e51032
DIFF: https://github.com/llvm/llvm-project/commit/1f9ca897987358053374b724444c2aa396e51032.diff
LOG: [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.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index bf822eb2c6eeb5..1a52f927d69f78 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -10299,8 +10299,12 @@ SDValue RISCVTargetLowering::lowerINSERT_SUBVECTOR(SDValue Op,
return Op;
}
+ // Use a insert_subvector that will resolve to an insert subreg.
+ assert(VLen);
+ unsigned Vscale = *VLen / RISCV::RVVBitsPerBlock;
SDValue Insert =
- DAG.getTargetInsertSubreg(SubRegIdx, DL, ContainerVecVT, Vec, SubVec);
+ DAG.getNode(ISD::INSERT_SUBVECTOR, DL, ContainerVecVT, Vec, SubVec,
+ DAG.getConstant(OrigIdx / Vscale, DL, XLenVT));
if (VecVT.isFixedLengthVector())
Insert = convertFromScalableVector(VecVT, Insert, DAG, Subtarget);
return Insert;
@@ -10316,8 +10320,10 @@ SDValue RISCVTargetLowering::lowerINSERT_SUBVECTOR(SDValue Op,
MVT InterSubVT = ContainerVecVT;
SDValue AlignedExtract = Vec;
unsigned AlignedIdx = OrigIdx - RemIdx.getKnownMinValue();
- if (SubVecVT.isFixedLengthVector())
+ if (SubVecVT.isFixedLengthVector()) {
+ assert(VLen);
AlignedIdx /= *VLen / RISCV::RVVBitsPerBlock;
+ }
if (ContainerVecVT.bitsGT(getLMUL1VT(ContainerVecVT))) {
InterSubVT = getLMUL1VT(ContainerVecVT);
// Extract a subvector equal to the nearest full vector register type. This
@@ -10494,10 +10500,14 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op,
// 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.
+ // using subregister manipulation. We use an extract_subvector that will
+ // resolve to an extract subreg.
if (RemIdx.isZero()) {
if (SubVecVT.isFixedLengthVector()) {
- Vec = DAG.getTargetExtractSubreg(SubRegIdx, DL, ContainerSubVecVT, Vec);
+ assert(VLen);
+ unsigned Vscale = *VLen / RISCV::RVVBitsPerBlock;
+ Vec = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, ContainerSubVecVT, Vec,
+ DAG.getConstant(OrigIdx / Vscale, DL, XLenVT));
return convertFromScalableVector(SubVecVT, Vec, DAG, Subtarget);
}
return Op;
@@ -10515,9 +10525,16 @@ SDValue RISCVTargetLowering::lowerEXTRACT_SUBVECTOR(SDValue Op,
if (VecVT.bitsGT(getLMUL1VT(VecVT))) {
// If VecVT has an LMUL > 1, then SubVecVT should have a smaller LMUL, and
// we should have successfully decomposed the extract into a subregister.
+ // We use an extract_subvector that will resolve to a subreg extract.
assert(SubRegIdx != RISCV::NoSubRegister);
+ unsigned Idx = OrigIdx - RemIdx.getKnownMinValue();
+ if (SubVecVT.isFixedLengthVector()) {
+ assert(VLen);
+ Idx /= *VLen / RISCV::RVVBitsPerBlock;
+ }
InterSubVT = getLMUL1VT(VecVT);
- Vec = DAG.getTargetExtractSubreg(SubRegIdx, DL, InterSubVT, Vec);
+ Vec = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, InterSubVT, Vec,
+ DAG.getConstant(Idx, DL, XLenVT));
}
// Slide this vector register down by the desired number of elements in order
More information about the llvm-commits
mailing list