Skip to content

Commit 2f9dfdf

Browse files
authored
[IR] Simplify scalable vector handling in ShuffleVectorInst::getShuffleMask. NFC (#143596)
Combine the scalable vector UndefValue check with the earlier ConstantAggregateZero handling for fixed and scalable vectors. Assert that the rest of the code is only reached for fixed vectors. Use append instead of resize since we know the size is increasing.
1 parent 54e72d1 commit 2f9dfdf

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

llvm/lib/IR/Instructions.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,23 +1854,18 @@ void ShuffleVectorInst::getShuffleMask(const Constant *Mask,
18541854
SmallVectorImpl<int> &Result) {
18551855
ElementCount EC = cast<VectorType>(Mask->getType())->getElementCount();
18561856

1857-
if (isa<ConstantAggregateZero>(Mask)) {
1858-
Result.resize(EC.getKnownMinValue(), 0);
1857+
if (isa<ConstantAggregateZero>(Mask) || isa<UndefValue>(Mask)) {
1858+
int MaskVal = isa<UndefValue>(Mask) ? -1 : 0;
1859+
Result.append(EC.getKnownMinValue(), MaskVal);
18591860
return;
18601861
}
18611862

1862-
Result.reserve(EC.getKnownMinValue());
1863+
assert(!EC.isScalable() &&
1864+
"Scalable vector shuffle mask must be undef or zeroinitializer");
18631865

1864-
if (EC.isScalable()) {
1865-
assert((isa<ConstantAggregateZero>(Mask) || isa<UndefValue>(Mask)) &&
1866-
"Scalable vector shuffle mask must be undef or zeroinitializer");
1867-
int MaskVal = isa<UndefValue>(Mask) ? -1 : 0;
1868-
for (unsigned I = 0; I < EC.getKnownMinValue(); ++I)
1869-
Result.emplace_back(MaskVal);
1870-
return;
1871-
}
1866+
unsigned NumElts = EC.getFixedValue();
18721867

1873-
unsigned NumElts = EC.getKnownMinValue();
1868+
Result.reserve(NumElts);
18741869

18751870
if (auto *CDS = dyn_cast<ConstantDataSequential>(Mask)) {
18761871
for (unsigned i = 0; i != NumElts; ++i)

0 commit comments

Comments
 (0)