Skip to content

Commit 35d218e

Browse files
committed
[RISCV] Use vslide1down idiom for generic build_vector
We had previously been going through the stack. A couple small notes: We have the vslide1down idiom in a few other places. As a post patch, I plan to try to common the code a bit. VF=2 case is still going through the splat + insert path. Picking the optimal sequence for this seems to be a bit fiddly (due to constant mat costs), so I restricted this to cases which would have previously hit the stack. I'm only handling integer vectors for the moment. Mostly because I don't see the existing vfslide1down ISD nodes being in place. This will be an obvious followup. One of the test diffs does expose a missing combine - a build_vector with a prefix coming from a vector extract sequence. The code after this is arguably worse (due to domain crossing vs stack store), but I think this is a narrow enough case to be non-blocking for now. Let me know if you disagree. Differential Revision: https://reviews.llvm.org/D149263
1 parent 657d20d commit 35d218e

14 files changed

+3195
-3658
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3186,7 +3186,24 @@ static SDValue lowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG,
31863186
return Vec;
31873187
}
31883188

3189-
return SDValue();
3189+
// For constant vectors, use generic constant pool lowering. Otherwise,
3190+
// we'd have to materialize constants in GPRs just to move them into the
3191+
// vector.
3192+
if (ISD::isBuildVectorOfConstantSDNodes(Op.getNode()))
3193+
return SDValue();
3194+
3195+
// We can use a series of vslide1down instructions to move values in GPRs
3196+
// into the appropriate place in the result vector. We use slide1down
3197+
// to avoid the register group overlap constraint of vslide1up.
3198+
if (VT.isFloatingPoint())
3199+
// TODO: Use vfslide1down.
3200+
return SDValue();
3201+
3202+
SDValue Vec = DAG.getUNDEF(ContainerVT);
3203+
for (const SDValue &V : Op->ops())
3204+
Vec = DAG.getNode(RISCVISD::VSLIDE1DOWN_VL, DL, ContainerVT,
3205+
DAG.getUNDEF(ContainerVT), Vec, V, Mask, VL);
3206+
return convertFromScalableVector(VT, Vec, DAG, Subtarget);
31903207
}
31913208

31923209
static SDValue splatPartsI64WithVL(const SDLoc &DL, MVT VT, SDValue Passthru,

llvm/test/CodeGen/RISCV/rvv/fixed-vector-shuffle-reverse.ll

Lines changed: 1972 additions & 2224 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)