Skip to content

Commit c846d26

Browse files
author
Francesco Petrogalli
committed
[llvm][Codegen] Make getVectorTypeBreakdownMVT work with scalable types.
Reviewers: efriedma, andwar, sdesmalen Reviewed By: efriedma Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77434
1 parent 9f87d95 commit c846d26

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

llvm/include/llvm/Support/TypeSize.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ElementCount {
3737
return { Min * RHS, Scalable };
3838
}
3939
ElementCount operator/(unsigned RHS) {
40+
assert(Min % RHS == 0 && "Min is not a multiple of RHS.");
4041
return { Min / RHS, Scalable };
4142
}
4243

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -944,42 +944,45 @@ static unsigned getVectorTypeBreakdownMVT(MVT VT, MVT &IntermediateVT,
944944
MVT &RegisterVT,
945945
TargetLoweringBase *TLI) {
946946
// Figure out the right, legal destination reg to copy into.
947-
unsigned NumElts = VT.getVectorNumElements();
947+
ElementCount EC = VT.getVectorElementCount();
948948
MVT EltTy = VT.getVectorElementType();
949949

950950
unsigned NumVectorRegs = 1;
951951

952-
// FIXME: We don't support non-power-of-2-sized vectors for now. Ideally we
953-
// could break down into LHS/RHS like LegalizeDAG does.
954-
if (!isPowerOf2_32(NumElts)) {
955-
NumVectorRegs = NumElts;
956-
NumElts = 1;
952+
// FIXME: We don't support non-power-of-2-sized vectors for now.
953+
// Ideally we could break down into LHS/RHS like LegalizeDAG does.
954+
if (!isPowerOf2_32(EC.Min)) {
955+
// Split EC to unit size (scalable property is preserved).
956+
NumVectorRegs = EC.Min;
957+
EC = EC / NumVectorRegs;
957958
}
958959

959-
// Divide the input until we get to a supported size. This will always
960-
// end with a scalar if the target doesn't support vectors.
961-
while (NumElts > 1 && !TLI->isTypeLegal(MVT::getVectorVT(EltTy, NumElts))) {
962-
NumElts >>= 1;
960+
// Divide the input until we get to a supported size. This will
961+
// always end up with an EC that represent a scalar or a scalable
962+
// scalar.
963+
while (EC.Min > 1 && !TLI->isTypeLegal(MVT::getVectorVT(EltTy, EC))) {
964+
EC.Min >>= 1;
963965
NumVectorRegs <<= 1;
964966
}
965967

966968
NumIntermediates = NumVectorRegs;
967969

968-
MVT NewVT = MVT::getVectorVT(EltTy, NumElts);
970+
MVT NewVT = MVT::getVectorVT(EltTy, EC);
969971
if (!TLI->isTypeLegal(NewVT))
970972
NewVT = EltTy;
971973
IntermediateVT = NewVT;
972974

973-
unsigned NewVTSize = NewVT.getSizeInBits();
975+
unsigned LaneSizeInBits = NewVT.getScalarSizeInBits().getFixedSize();
974976

975977
// Convert sizes such as i33 to i64.
976-
if (!isPowerOf2_32(NewVTSize))
977-
NewVTSize = NextPowerOf2(NewVTSize);
978+
if (!isPowerOf2_32(LaneSizeInBits))
979+
LaneSizeInBits = NextPowerOf2(LaneSizeInBits);
978980

979981
MVT DestVT = TLI->getRegisterType(NewVT);
980982
RegisterVT = DestVT;
981983
if (EVT(DestVT).bitsLT(NewVT)) // Value is expanded, e.g. i64 -> i16.
982-
return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
984+
return NumVectorRegs *
985+
(LaneSizeInBits / DestVT.getScalarSizeInBits().getFixedSize());
983986

984987
// Otherwise, promotion or legal types use the same number of registers as
985988
// the vector decimated to the appropriate level.

0 commit comments

Comments
 (0)