Skip to content

Commit ad0acf9

Browse files
[GISEL] More accounting for scalable vectors when operating on LLTs (llvm#80372)
This is stacked on by llvm#80377 and llvm#80378
1 parent 7ca4012 commit ad0acf9

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

llvm/lib/CodeGen/GlobalISel/CallLowering.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static void buildCopyFromRegs(MachineIRBuilder &B, ArrayRef<Register> OrigRegs,
412412
// size, e.g. PartLLT == v2s64 and LLTy is v3s32, then first coerce it to
413413
// have the same elt type, i.e. v4s32.
414414
// TODO: Extend this coersion to element multiples other than just 2.
415-
if (PartLLT.getSizeInBits() > LLTy.getSizeInBits() &&
415+
if (TypeSize::isKnownGT(PartLLT.getSizeInBits(), LLTy.getSizeInBits()) &&
416416
PartLLT.getScalarSizeInBits() == LLTy.getScalarSizeInBits() * 2 &&
417417
Regs.size() == 1) {
418418
LLT NewTy = PartLLT.changeElementType(LLTy.getElementType())
@@ -529,7 +529,7 @@ static void buildCopyToRegs(MachineIRBuilder &B, ArrayRef<Register> DstRegs,
529529
// We could just insert a regular copy, but this is unreachable at the moment.
530530
assert(SrcTy != PartTy && "identical part types shouldn't reach here");
531531

532-
const unsigned PartSize = PartTy.getSizeInBits();
532+
const TypeSize PartSize = PartTy.getSizeInBits();
533533

534534
if (PartTy.isVector() == SrcTy.isVector() &&
535535
PartTy.getScalarSizeInBits() > SrcTy.getScalarSizeInBits()) {
@@ -539,7 +539,7 @@ static void buildCopyToRegs(MachineIRBuilder &B, ArrayRef<Register> DstRegs,
539539
}
540540

541541
if (SrcTy.isVector() && !PartTy.isVector() &&
542-
PartSize > SrcTy.getElementType().getSizeInBits()) {
542+
TypeSize::isKnownGT(PartSize, SrcTy.getElementType().getSizeInBits())) {
543543
// Vector was scalarized, and the elements extended.
544544
auto UnmergeToEltTy = B.buildUnmerge(SrcTy.getElementType(), SrcReg);
545545
for (int i = 0, e = DstRegs.size(); i != e; ++i)
@@ -548,9 +548,10 @@ static void buildCopyToRegs(MachineIRBuilder &B, ArrayRef<Register> DstRegs,
548548
}
549549

550550
if (SrcTy.isVector() && PartTy.isVector() &&
551-
PartTy.getScalarSizeInBits() == SrcTy.getScalarSizeInBits() &&
552-
SrcTy.getNumElements() < PartTy.getNumElements()) {
553-
// A coercion like: v2f32 -> v4f32.
551+
PartTy.getSizeInBits() == SrcTy.getSizeInBits() &&
552+
ElementCount::isKnownLT(SrcTy.getElementCount(),
553+
PartTy.getElementCount())) {
554+
// A coercion like: v2f32 -> v4f32 or nxv2f32 -> nxv4f32
554555
Register DstReg = DstRegs.front();
555556
B.buildPadVectorWithUndefElements(DstReg, SrcReg);
556557
return;

llvm/lib/CodeGen/GlobalISel/Utils.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,12 +1117,18 @@ LLT llvm::getLCMType(LLT OrigTy, LLT TargetTy) {
11171117
}
11181118

11191119
LLT llvm::getCoverTy(LLT OrigTy, LLT TargetTy) {
1120+
1121+
if ((OrigTy.isScalableVector() && TargetTy.isFixedVector()) ||
1122+
(OrigTy.isFixedVector() && TargetTy.isScalableVector()))
1123+
llvm_unreachable(
1124+
"getCoverTy not implemented between fixed and scalable vectors.");
1125+
11201126
if (!OrigTy.isVector() || !TargetTy.isVector() || OrigTy == TargetTy ||
11211127
(OrigTy.getScalarSizeInBits() != TargetTy.getScalarSizeInBits()))
11221128
return getLCMType(OrigTy, TargetTy);
11231129

1124-
unsigned OrigTyNumElts = OrigTy.getNumElements();
1125-
unsigned TargetTyNumElts = TargetTy.getNumElements();
1130+
unsigned OrigTyNumElts = OrigTy.getElementCount().getKnownMinValue();
1131+
unsigned TargetTyNumElts = TargetTy.getElementCount().getKnownMinValue();
11261132
if (OrigTyNumElts % TargetTyNumElts == 0)
11271133
return OrigTy;
11281134

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,8 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
14001400
if (DstTy.isVector()) {
14011401
// This case is the converse of G_CONCAT_VECTORS.
14021402
if (!SrcTy.isVector() || SrcTy.getScalarType() != DstTy.getScalarType() ||
1403-
SrcTy.getNumElements() != NumDsts * DstTy.getNumElements())
1403+
SrcTy.isScalableVector() != DstTy.isScalableVector() ||
1404+
SrcTy.getSizeInBits() != NumDsts * DstTy.getSizeInBits())
14041405
report("G_UNMERGE_VALUES source operand does not match vector "
14051406
"destination operands",
14061407
MI);
@@ -1477,8 +1478,8 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
14771478
for (const MachineOperand &MO : llvm::drop_begin(MI->operands(), 2))
14781479
if (MRI->getType(MI->getOperand(1).getReg()) != MRI->getType(MO.getReg()))
14791480
report("G_CONCAT_VECTOR source operand types are not homogeneous", MI);
1480-
if (DstTy.getNumElements() !=
1481-
SrcTy.getNumElements() * (MI->getNumOperands() - 1))
1481+
if (DstTy.getElementCount() !=
1482+
SrcTy.getElementCount() * (MI->getNumOperands() - 1))
14821483
report("G_CONCAT_VECTOR num dest and source elements should match", MI);
14831484
break;
14841485
}

0 commit comments

Comments
 (0)