[llvm] 2f9dfdf - [IR] Simplify scalable vector handling in ShuffleVectorInst::getShuffleMask. NFC (#143596)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 10 15:11:47 PDT 2025
Author: Craig Topper
Date: 2025-06-10T15:11:44-07:00
New Revision: 2f9dfdfb35bdb10334b09476a47dc1d93beea96c
URL: https://github.com/llvm/llvm-project/commit/2f9dfdfb35bdb10334b09476a47dc1d93beea96c
DIFF: https://github.com/llvm/llvm-project/commit/2f9dfdfb35bdb10334b09476a47dc1d93beea96c.diff
LOG: [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.
Added:
Modified:
llvm/lib/IR/Instructions.cpp
Removed:
################################################################################
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<int> &Result) {
ElementCount EC = cast<VectorType>(Mask->getType())->getElementCount();
- if (isa<ConstantAggregateZero>(Mask)) {
- Result.resize(EC.getKnownMinValue(), 0);
+ if (isa<ConstantAggregateZero>(Mask) || isa<UndefValue>(Mask)) {
+ int MaskVal = isa<UndefValue>(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<ConstantAggregateZero>(Mask) || isa<UndefValue>(Mask)) &&
- "Scalable vector shuffle mask must be undef or zeroinitializer");
- int MaskVal = isa<UndefValue>(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<ConstantDataSequential>(Mask)) {
for (unsigned i = 0; i != NumElts; ++i)
More information about the llvm-commits
mailing list