[llvm] [SLP][NFC] Make calculateTreeCostAndTrimNonProfitable compatible (PR #191905)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 13 15:51:42 PDT 2026
https://github.com/alexey-bataev created https://github.com/llvm/llvm-project/pull/191905
with processBuildVector, NFC
processBuildVector adjusts the scalars to match the entry vector factor,
while calculateTreeCostAndTrimNonProfitable does not. Sync the behovior
to avoid potential issues. Currently it does not affect the cost
estimations, so it is NFC.
>From eb42df343349903a78997620f7fd378659bcf912 Mon Sep 17 00:00:00 2001
From: Alexey Bataev <a.bataev at outlook.com>
Date: Mon, 13 Apr 2026 15:51:29 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.7
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 0e647fa235916..803507f110007 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -18075,20 +18075,18 @@ InstructionCost BoUpSLP::calculateTreeCostAndTrimNonProfitable(
Worklist.pop();
continue;
}
- const unsigned Sz = TE->Scalars.size();
- APInt DemandedElts = APInt::getAllOnes(Sz);
+ const unsigned EntryVF = TE->getVectorFactor();
+ APInt DemandedElts = APInt::getZero(EntryVF);
for (auto [Idx, V] : enumerate(TE->Scalars)) {
- if (isConstant(V))
- DemandedElts.clearBit(Idx);
+ if (!isConstant(V))
+ DemandedElts.setBit(Idx);
}
Type *ScalarTy = getValueType(TE->Scalars.front());
auto It = MinBWs.find(TE);
if (It != MinBWs.end())
ScalarTy = IntegerType::get(ScalarTy->getContext(), It->second.first);
- auto *VecTy = getWidenedType(ScalarTy, Sz);
- const unsigned EntryVF = TE->getVectorFactor();
- auto *FinalVecTy = getWidenedType(ScalarTy, EntryVF);
+ auto *VecTy = getWidenedType(ScalarTy, EntryVF);
InstructionCost GatherCost = ::getScalarizationOverhead(
*TTI, ScalarTy, VecTy, DemandedElts,
/*Insert=*/true, /*Extract=*/false, CostKind);
@@ -18111,7 +18109,7 @@ InstructionCost BoUpSLP::calculateTreeCostAndTrimNonProfitable(
::addMask(Mask, TE->ReuseShuffleIndices);
if (!Mask.empty() && !ShuffleVectorInst::isIdentityMask(Mask, EntryVF))
GatherCost +=
- ::getShuffleCost(*TTI, TTI::SK_PermuteSingleSrc, FinalVecTy, Mask);
+ ::getShuffleCost(*TTI, TTI::SK_PermuteSingleSrc, VecTy, Mask);
// If all scalars are reused in gather node(s) or other vector nodes, there
// might be extra cost for inserting them.
if ((!TE->hasState() || !TE->isAltShuffle()) &&
More information about the llvm-commits
mailing list