Skip to content

[RISCV] Change vector tuple type's TypeSize to scalable #114329

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 6 commits into from
Nov 17, 2024
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
5 changes: 3 additions & 2 deletions llvm/include/llvm/CodeGenTypes/MachineValueType.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace llvm {

/// Return true if this is a custom target type that has a scalable size.
bool isScalableTargetExtVT() const {
return SimpleTy == MVT::aarch64svcount;
return SimpleTy == MVT::aarch64svcount || isRISCVVectorTuple();
}

/// Return true if the type is a scalable type.
Expand Down Expand Up @@ -308,7 +308,8 @@ namespace llvm {
TypeSize getSizeInBits() const {
static constexpr TypeSize SizeTable[] = {
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
TypeSize(Sz, Sc || Ty == aarch64svcount /* FIXME: Not in the td. */),
TypeSize(Sz, Sc || Tup || Ty == aarch64svcount /* FIXME: Not in the td. \
*/),
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_ATTR
};
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/ValueTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ std::string EVT::getEVTString() const {
switch (V.SimpleTy) {
default:
if (isRISCVVectorTuple()) {
unsigned Sz = getSizeInBits();
unsigned Sz = getSizeInBits().getKnownMinValue();
unsigned NF = getRISCVVectorTupleNumFields();
unsigned MinNumElts = Sz / (NF * 8);
return "riscv_nxv" + utostr(MinNumElts) + "i8x" + utostr(NF);
Expand Down
46 changes: 26 additions & 20 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2416,8 +2416,9 @@ unsigned RISCVTargetLowering::getSubregIndexByMVT(MVT VT, unsigned Index) {
unsigned RISCVTargetLowering::getRegClassIDForVecVT(MVT VT) {
if (VT.isRISCVVectorTuple()) {
unsigned NF = VT.getRISCVVectorTupleNumFields();
unsigned RegsPerField = std::max(1U, (unsigned)VT.getSizeInBits() /
(NF * RISCV::RVVBitsPerBlock));
unsigned RegsPerField =
std::max(1U, (unsigned)VT.getSizeInBits().getKnownMinValue() /
(NF * RISCV::RVVBitsPerBlock));
switch (RegsPerField) {
case 1:
if (NF == 2)
Expand Down Expand Up @@ -7006,7 +7007,7 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
SDLoc DL(Op);
MVT XLenVT = Subtarget.getXLenVT();
unsigned NF = VecTy.getRISCVVectorTupleNumFields();
unsigned Sz = VecTy.getSizeInBits();
unsigned Sz = VecTy.getSizeInBits().getKnownMinValue();
unsigned NumElts = Sz / (NF * 8);
int Log2LMUL = Log2_64(NumElts) - 3;

Expand Down Expand Up @@ -7049,7 +7050,7 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
SDLoc DL(Op);
MVT XLenVT = Subtarget.getXLenVT();
unsigned NF = VecTy.getRISCVVectorTupleNumFields();
unsigned Sz = VecTy.getSizeInBits();
unsigned Sz = VecTy.getSizeInBits().getKnownMinValue();
unsigned NumElts = Sz / (NF * 8);
int Log2LMUL = Log2_64(NumElts) - 3;

Expand Down Expand Up @@ -21309,6 +21310,27 @@ bool RISCVTargetLowering::splitValueIntoRegisterParts(
return true;
}

if (ValueVT.isRISCVVectorTuple() && PartVT.isRISCVVectorTuple()) {
#ifndef NDEBUG
unsigned ValNF = ValueVT.getRISCVVectorTupleNumFields();
[[maybe_unused]] unsigned ValLMUL =
divideCeil(ValueVT.getSizeInBits().getKnownMinValue(),
ValNF * RISCV::RVVBitsPerBlock);
unsigned PartNF = PartVT.getRISCVVectorTupleNumFields();
[[maybe_unused]] unsigned PartLMUL =
divideCeil(PartVT.getSizeInBits().getKnownMinValue(),
PartNF * RISCV::RVVBitsPerBlock);
assert(ValNF == PartNF && ValLMUL == PartLMUL &&
"RISC-V vector tuple type only accepts same register class type "
"TUPLE_INSERT");
#endif

Val = DAG.getNode(RISCVISD::TUPLE_INSERT, DL, PartVT, DAG.getUNDEF(PartVT),
Val, DAG.getVectorIdxConstant(0, DL));
Parts[0] = Val;
return true;
}

if (ValueVT.isScalableVector() && PartVT.isScalableVector()) {
LLVMContext &Context = *DAG.getContext();
EVT ValueEltVT = ValueVT.getVectorElementType();
Expand Down Expand Up @@ -21344,22 +21366,6 @@ bool RISCVTargetLowering::splitValueIntoRegisterParts(
}
}

if (ValueVT.isRISCVVectorTuple() && PartVT.isRISCVVectorTuple()) {
unsigned ValNF = ValueVT.getRISCVVectorTupleNumFields();
[[maybe_unused]] unsigned ValLMUL =
divideCeil(ValueVT.getSizeInBits(), ValNF * RISCV::RVVBitsPerBlock);
unsigned PartNF = PartVT.getRISCVVectorTupleNumFields();
[[maybe_unused]] unsigned PartLMUL =
divideCeil(PartVT.getSizeInBits(), PartNF * RISCV::RVVBitsPerBlock);
assert(ValNF == PartNF && ValLMUL == PartLMUL &&
"RISC-V vector tuple type only accepts same register class type "
"TUPLE_INSERT");

Val = DAG.getNode(RISCVISD::TUPLE_INSERT, DL, PartVT, DAG.getUNDEF(PartVT),
Val, DAG.getVectorIdxConstant(0, DL));
Parts[0] = Val;
return true;
}
return false;
}

Expand Down
Loading