Skip to content
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

[RISCV] Fold vector shift of sext/zext to widening multiply #121563

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
[RISCV] Handle fixed-length vectors
  • Loading branch information
pfusik committed Jan 9, 2025
commit 174e59e5be1d1c85d2e361551f96e6b542dd38e9
33 changes: 23 additions & 10 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17364,6 +17364,9 @@ static SDValue combineSHL(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
case ISD::ZERO_EXTEND:
Opcode = RISCVISD::VWMULU_VL;
break;
// TODO:
// case RISCVISD::VSEXT_VL:
// case RISCVISD::VZEXT_VL:
default:
return SDValue();
}
Expand All @@ -17386,23 +17389,30 @@ static SDValue combineSHL(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
return SDValue();

SDValue NarrowOp = LHS.getOperand(0);
uint64_t NarrowBits = NarrowOp.getSimpleValueType().getScalarSizeInBits();
MVT NarrowVT = NarrowOp.getSimpleValueType();
uint64_t NarrowBits = NarrowVT.getScalarSizeInBits();
if (ShAmtInt >= NarrowBits)
return SDValue();
EVT VT = N->getValueType(0);
MVT VT = N->getSimpleValueType(0);
if (NarrowBits * 2 != VT.getScalarSizeInBits())
return SDValue();

SelectionDAG &DAG = DCI.DAG;
MVT NarrowContainerVT = NarrowVT;
MVT ContainerVT = VT;
SDLoc DL(N);
SDValue Passthru, Mask, VL;
switch (N->getOpcode()) {
case ISD::SHL:
if (!VT.isScalableVector())
return SDValue(); // TODO: handle fixed length vectors
if (VT.isFixedLengthVector()) {
NarrowContainerVT =
getContainerForFixedLengthVector(DAG, NarrowVT, Subtarget);
NarrowOp =
convertToScalableVector(NarrowContainerVT, NarrowOp, DAG, Subtarget);
ContainerVT = getContainerForFixedLengthVector(DAG, VT, Subtarget);
}
Passthru = DAG.getUNDEF(VT);
std::tie(Mask, VL) =
getDefaultScalableVLOps(VT.getSimpleVT(), DL, DAG, Subtarget);
std::tie(Mask, VL) = getDefaultVLOps(VT, ContainerVT, DL, DAG, Subtarget);
break;
case RISCVISD::SHL_VL:
Passthru = N->getOperand(2);
Expand All @@ -17412,10 +17422,13 @@ static SDValue combineSHL(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
default:
llvm_unreachable("Expected SHL");
}
return DAG.getNode(
Opcode, DL, VT, NarrowOp,
DAG.getConstant(1ULL << ShAmtInt, SDLoc(RHS), NarrowOp.getValueType()),
Passthru, Mask, VL);
SDValue Mul =
DAG.getNode(Opcode, DL, ContainerVT, NarrowOp,
DAG.getConstant(1ULL << ShAmtInt, SDLoc(RHS), ContainerVT),
Passthru, Mask, VL);
if (VT.isFixedLengthVector())
return convertFromScalableVector(VT, Mul, DAG, Subtarget);
return Mul;
}

SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
Expand Down
Loading
Loading