[IR] Support scalable vectors in ShuffleVectorInst::increasesLength

Since the length of the llvm::SmallVector shufflemask is related to the
minimum number of elements in a scalable vector, it is fine to just get
the Min field of the ElementCount. This is already done for the similar
function changesLength, tests have been added for both.

Reviewed By: sdesmalen

Differential Revision: https://reviews.llvm.org/D92472
This commit is contained in:
Cullen Rhodes 2020-11-30 11:35:46 +00:00
parent 6bf29dbb15
commit 9b01896555
2 changed files with 15 additions and 2 deletions

View File

@ -2081,8 +2081,9 @@ public:
/// elements than its source vectors.
/// Example: shufflevector <2 x n> A, <2 x n> B, <1,2,3>
bool increasesLength() const {
unsigned NumSourceElts =
cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
unsigned NumSourceElts = cast<VectorType>(Op<0>()->getType())
->getElementCount()
.getKnownMinValue();
unsigned NumMaskElts = ShuffleMask.size();
return NumSourceElts < NumMaskElts;
}

View File

@ -1083,7 +1083,19 @@ TEST(InstructionsTest, ShuffleMaskQueries) {
Constant::getNullValue(VScaleV4Int32Ty));
int Index = 0;
EXPECT_FALSE(Id13->isExtractSubvectorMask(Index));
EXPECT_FALSE(Id13->changesLength());
EXPECT_FALSE(Id13->increasesLength());
delete Id13;
// Result has twice as many operands.
Type *VScaleV2Int32Ty = ScalableVectorType::get(Int32Ty, 2);
ShuffleVectorInst *Id14 =
new ShuffleVectorInst(Constant::getAllOnesValue(VScaleV2Int32Ty),
UndefValue::get(VScaleV2Int32Ty),
Constant::getNullValue(VScaleV4Int32Ty));
EXPECT_TRUE(Id14->changesLength());
EXPECT_TRUE(Id14->increasesLength());
delete Id14;
}
TEST(InstructionsTest, GetSplat) {