From a230b008542503ebe51db02668292c60f524a6d0 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 10 Jun 2025 12:06:50 -0700 Subject: [PATCH] [IR] Simplify scalable vector handling in ShuffleVectorInst::getShuffleMask. 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. --- llvm/lib/IR/Instructions.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index b29969657e7fc..2d89ec1b0a8d3 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -1854,23 +1854,18 @@ void ShuffleVectorInst::getShuffleMask(const Constant *Mask, SmallVectorImpl &Result) { ElementCount EC = cast(Mask->getType())->getElementCount(); - if (isa(Mask)) { - Result.resize(EC.getKnownMinValue(), 0); + if (isa(Mask) || isa(Mask)) { + int MaskVal = isa(Mask) ? -1 : 0; + Result.append(EC.getKnownMinValue(), MaskVal); return; } - Result.reserve(EC.getKnownMinValue()); + assert(!EC.isScalable() && + "Scalable vector shuffle mask must be undef or zeroinitializer"); - if (EC.isScalable()) { - assert((isa(Mask) || isa(Mask)) && - "Scalable vector shuffle mask must be undef or zeroinitializer"); - int MaskVal = isa(Mask) ? -1 : 0; - for (unsigned I = 0; I < EC.getKnownMinValue(); ++I) - Result.emplace_back(MaskVal); - return; - } + unsigned NumElts = EC.getFixedValue(); - unsigned NumElts = EC.getKnownMinValue(); + Result.reserve(NumElts); if (auto *CDS = dyn_cast(Mask)) { for (unsigned i = 0; i != NumElts; ++i)