Skip to content

[RISCV] Support scalable vectors for the zvqdotq lowering paths #140922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18177,17 +18177,20 @@ static SDValue lowerVQDOT(unsigned Opc, SDValue Op0, SDValue Op1,
assert(VT == Op1.getSimpleValueType() &&
VT.getVectorElementType() == MVT::i32);

assert(VT.isFixedLengthVector());
MVT ContainerVT = getContainerForFixedLengthVector(DAG, VT, Subtarget);
SDValue Passthru = convertToScalableVector(
ContainerVT, DAG.getConstant(0, DL, VT), DAG, Subtarget);
Op0 = convertToScalableVector(ContainerVT, Op0, DAG, Subtarget);
Op1 = convertToScalableVector(ContainerVT, Op1, DAG, Subtarget);

SDValue Passthru = DAG.getConstant(0, DL, VT);
MVT ContainerVT = VT;
if (VT.isFixedLengthVector()) {
ContainerVT = getContainerForFixedLengthVector(DAG, VT, Subtarget);
Passthru = convertToScalableVector(ContainerVT, Passthru, DAG, Subtarget);
Op0 = convertToScalableVector(ContainerVT, Op0, DAG, Subtarget);
Op1 = convertToScalableVector(ContainerVT, Op1, DAG, Subtarget);
}
auto [Mask, VL] = getDefaultVLOps(VT, ContainerVT, DL, DAG, Subtarget);
SDValue LocalAccum = DAG.getNode(Opc, DL, ContainerVT,
{Op0, Op1, Passthru, Mask, VL});
return convertFromScalableVector(VT, LocalAccum, DAG, Subtarget);
if (VT.isFixedLengthVector())
return convertFromScalableVector(VT, LocalAccum, DAG, Subtarget);
return LocalAccum;
}

static MVT getQDOTXResultType(MVT OpVT) {
Expand All @@ -18207,7 +18210,7 @@ static SDValue getZeroPaddedAdd(const SDLoc &DL, SDValue A, SDValue B,
EVT AVT = A.getValueType();
EVT BVT = B.getValueType();
assert(AVT.getVectorElementType() == BVT.getVectorElementType());
if (AVT.getVectorNumElements() > BVT.getVectorNumElements()) {
if (AVT.getVectorMinNumElements() > BVT.getVectorMinNumElements()) {
std::swap(A, B);
std::swap(AVT, BVT);
}
Expand Down Expand Up @@ -18641,17 +18644,19 @@ static SDValue combineToVWMACC(SDNode *N, SelectionDAG &DAG,
static SDValue combineVqdotAccum(SDNode *N, SelectionDAG &DAG,
const RISCVSubtarget &Subtarget) {

assert(N->getOpcode() == RISCVISD::ADD_VL);
assert(N->getOpcode() == RISCVISD::ADD_VL || N->getOpcode() == ISD::ADD);

if (!N->getValueType(0).isVector())
return SDValue();

SDValue Addend = N->getOperand(0);
SDValue DotOp = N->getOperand(1);

SDValue AddPassthruOp = N->getOperand(2);
if (!AddPassthruOp.isUndef())
return SDValue();
if (N->getOpcode() == RISCVISD::ADD_VL) {
SDValue AddPassthruOp = N->getOperand(2);
if (!AddPassthruOp.isUndef())
return SDValue();
}

auto IsVqdotqOpc = [](unsigned Opc) {
switch (Opc) {
Expand All @@ -18670,8 +18675,15 @@ static SDValue combineVqdotAccum(SDNode *N, SelectionDAG &DAG,
if (!IsVqdotqOpc(DotOp.getOpcode()))
return SDValue();

SDValue AddMask = N->getOperand(3);
SDValue AddVL = N->getOperand(4);
auto [AddMask, AddVL] = [](SDNode *N, SelectionDAG &DAG,
const RISCVSubtarget &Subtarget) {
if (N->getOpcode() == ISD::ADD) {
SDLoc DL(N);
return getDefaultScalableVLOps(N->getSimpleValueType(0), DL, DAG,
Subtarget);
}
return std::make_pair(N->getOperand(3), N->getOperand(4));
}(N, DAG, Subtarget);

SDValue MulVL = DotOp.getOperand(4);
if (AddVL != MulVL)
Expand Down Expand Up @@ -19309,6 +19321,8 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
return V;
if (SDValue V = combineToVWMACC(N, DAG, Subtarget))
return V;
if (SDValue V = combineVqdotAccum(N, DAG, Subtarget))
return V;
return performADDCombine(N, DCI, Subtarget);
}
case ISD::SUB: {
Expand Down
Loading
Loading