Skip to content

Commit 4582651

Browse files
committed
[SLP][NFC]Fix clang-tidy suggestions, cleanup, NFC.
1 parent 8ab7718 commit 4582651

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,8 +1153,8 @@ static void fixupOrderingIndices(MutableArrayRef<unsigned> Order) {
11531153

11541154
/// \returns a bitset for selecting opcodes. false for Opcode0 and true for
11551155
/// Opcode1.
1156-
SmallBitVector getAltInstrMask(ArrayRef<Value *> VL, unsigned Opcode0,
1157-
unsigned Opcode1) {
1156+
static SmallBitVector getAltInstrMask(ArrayRef<Value *> VL, unsigned Opcode0,
1157+
unsigned Opcode1) {
11581158
Type *ScalarTy = VL[0]->getType();
11591159
unsigned ScalarTyNumElements = getNumElements(ScalarTy);
11601160
SmallBitVector OpcodeMask(VL.size() * ScalarTyNumElements, false);
@@ -1371,7 +1371,7 @@ class BoUpSLP {
13711371
MustGather.clear();
13721372
NonScheduledFirst.clear();
13731373
EntryToLastInstruction.clear();
1374-
GatheredLoadsEntriesFirst = NoGatheredLoads;
1374+
GatheredLoadsEntriesFirst.reset();
13751375
ExternalUses.clear();
13761376
ExternalUsesAsOriginalScalar.clear();
13771377
for (auto &Iter : BlocksSchedules) {
@@ -3193,7 +3193,7 @@ class BoUpSLP {
31933193
SmallVector<EdgeInfo, 1> UserTreeIndices;
31943194

31953195
/// The index of this treeEntry in VectorizableTree.
3196-
int Idx = -1;
3196+
unsigned Idx = 0;
31973197

31983198
/// For gather/buildvector/alt opcode (TODO) nodes, which are combined from
31993199
/// other nodes as a series of insertvector instructions.
@@ -3461,7 +3461,7 @@ class BoUpSLP {
34613461
(Bundle && EntryState != TreeEntry::NeedToGather)) &&
34623462
"Need to vectorize gather entry?");
34633463
// Gathered loads still gathered? Do not create entry, use the original one.
3464-
if (GatheredLoadsEntriesFirst != NoGatheredLoads &&
3464+
if (GatheredLoadsEntriesFirst.has_value() &&
34653465
EntryState == TreeEntry::NeedToGather &&
34663466
S.getOpcode() == Instruction::Load && UserTreeIdx.EdgeIdx == UINT_MAX &&
34673467
!UserTreeIdx.UserTE)
@@ -3614,8 +3614,7 @@ class BoUpSLP {
36143614
ValueToGatherNodesMap ValueToGatherNodes;
36153615

36163616
/// The index of the first gathered load entry in the VectorizeTree.
3617-
constexpr static int NoGatheredLoads = -1;
3618-
int GatheredLoadsEntriesFirst = NoGatheredLoads;
3617+
std::optional<unsigned> GatheredLoadsEntriesFirst;
36193618

36203619
/// This POD struct describes one external user in the vectorized tree.
36213620
struct ExternalUser {
@@ -6971,9 +6970,9 @@ void BoUpSLP::tryToVectorizeGatheredLoads(
69716970
}
69726971
// If no new entries created, consider it as no gathered loads entries must be
69736972
// handled.
6974-
if (static_cast<unsigned>(GatheredLoadsEntriesFirst) ==
6973+
if (static_cast<unsigned>(*GatheredLoadsEntriesFirst) ==
69756974
VectorizableTree.size())
6976-
GatheredLoadsEntriesFirst = NoGatheredLoads;
6975+
GatheredLoadsEntriesFirst.reset();
69776976
}
69786977

69796978
/// \return true if the specified list of values has only one instruction that
@@ -7704,7 +7703,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
77047703
if (S.getOpcode()) {
77057704
if (TreeEntry *E = getTreeEntry(S.OpValue)) {
77067705
LLVM_DEBUG(dbgs() << "SLP: \tChecking bundle: " << *S.OpValue << ".\n");
7707-
if (GatheredLoadsEntriesFirst != NoGatheredLoads || !E->isSame(VL)) {
7706+
if (GatheredLoadsEntriesFirst.has_value() || !E->isSame(VL)) {
77087707
auto It = MultiNodeScalars.find(S.OpValue);
77097708
if (It != MultiNodeScalars.end()) {
77107709
auto *TEIt = find_if(It->getSecond(),
@@ -11094,9 +11093,9 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
1109411093
"Not supported shufflevector usage.");
1109511094
auto *SV = cast<ShuffleVectorInst>(V);
1109611095
int Index;
11097-
[[maybe_unused]] bool isExtractSubvectorMask =
11096+
[[maybe_unused]] bool IsExtractSubvectorMask =
1109811097
SV->isExtractSubvectorMask(Index);
11099-
assert(isExtractSubvectorMask &&
11098+
assert(IsExtractSubvectorMask &&
1110011099
"Not supported shufflevector usage.");
1110111100
if (NextIndex != Index)
1110211101
return false;
@@ -11822,8 +11821,8 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) {
1182211821
KeepScalar = true;
1182311822
} else if (KeepScalar && ScalarCost != TTI::TCC_Free &&
1182411823
ExtraCost - ScalarCost <= TTI::TCC_Basic &&
11825-
(GatheredLoadsEntriesFirst == NoGatheredLoads ||
11826-
Entry->Idx < GatheredLoadsEntriesFirst)) {
11824+
(!GatheredLoadsEntriesFirst.has_value() ||
11825+
Entry->Idx < *GatheredLoadsEntriesFirst)) {
1182711826
unsigned ScalarUsesCount = count_if(Entry->Scalars, [&](Value *V) {
1182811827
return ValueToExtUses->contains(V);
1182911828
});
@@ -12281,7 +12280,7 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(
1228112280
VToTEs.insert(TEPtr);
1228212281
}
1228312282
if (const TreeEntry *VTE = getTreeEntry(V)) {
12284-
if (ForOrder && VTE->Idx < GatheredLoadsEntriesFirst) {
12283+
if (ForOrder && VTE->Idx < GatheredLoadsEntriesFirst.value_or(0)) {
1228512284
if (VTE->State != TreeEntry::Vectorize) {
1228612285
auto It = MultiNodeScalars.find(V);
1228712286
if (It == MultiNodeScalars.end())
@@ -12560,7 +12559,7 @@ BoUpSLP::isGatherShuffledEntry(
1256012559
Entries.clear();
1256112560
// No need to check for the topmost gather node.
1256212561
if (TE == VectorizableTree.front().get() &&
12563-
(GatheredLoadsEntriesFirst == NoGatheredLoads ||
12562+
(!GatheredLoadsEntriesFirst.has_value() ||
1256412563
none_of(ArrayRef(VectorizableTree).drop_front(),
1256512564
[](const std::unique_ptr<TreeEntry> &TE) {
1256612565
return !TE->isGather();
@@ -12712,9 +12711,9 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
1271212711
// constant indices or gathered loads).
1271312712
auto *Front = E->getMainOp();
1271412713
auto *BB = Front->getParent();
12715-
assert(((GatheredLoadsEntriesFirst != NoGatheredLoads &&
12714+
assert(((GatheredLoadsEntriesFirst.has_value() &&
1271612715
E->getOpcode() == Instruction::Load && E->isGather() &&
12717-
E->Idx < GatheredLoadsEntriesFirst) ||
12716+
E->Idx < *GatheredLoadsEntriesFirst) ||
1271812717
all_of(E->Scalars,
1271912718
[=](Value *V) -> bool {
1272012719
if (E->getOpcode() == Instruction::GetElementPtr &&
@@ -12742,9 +12741,9 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
1274212741
!isa<GetElementPtrInst>(I)) ||
1274312742
(isVectorLikeInstWithConstOps(LastInst) &&
1274412743
isVectorLikeInstWithConstOps(I)) ||
12745-
(GatheredLoadsEntriesFirst != NoGatheredLoads &&
12744+
(GatheredLoadsEntriesFirst.has_value() &&
1274612745
E->getOpcode() == Instruction::Load && E->isGather() &&
12747-
E->Idx < GatheredLoadsEntriesFirst)) &&
12746+
E->Idx < *GatheredLoadsEntriesFirst)) &&
1274812747
"Expected vector-like or non-GEP in GEP node insts only.");
1274912748
if (!DT->isReachableFromEntry(LastInst->getParent())) {
1275012749
LastInst = I;
@@ -12802,8 +12801,8 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
1280212801
};
1280312802

1280412803
// Set insertpoint for gathered loads to the very first load.
12805-
if (GatheredLoadsEntriesFirst != NoGatheredLoads &&
12806-
E->Idx >= GatheredLoadsEntriesFirst && !E->isGather() &&
12804+
if (GatheredLoadsEntriesFirst.has_value() &&
12805+
E->Idx >= *GatheredLoadsEntriesFirst && !E->isGather() &&
1280712806
E->getOpcode() == Instruction::Load) {
1280812807
Res = FindFirstInst();
1280912808
return *Res;
@@ -15181,8 +15180,8 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,
1518115180
// Emit gathered loads first to emit better code for the users of those
1518215181
// gathered loads.
1518315182
for (const std::unique_ptr<TreeEntry> &TE : VectorizableTree) {
15184-
if (GatheredLoadsEntriesFirst != NoGatheredLoads &&
15185-
TE->Idx >= GatheredLoadsEntriesFirst &&
15183+
if (GatheredLoadsEntriesFirst.has_value() &&
15184+
TE->Idx >= *GatheredLoadsEntriesFirst &&
1518615185
(!TE->isGather() || !TE->UserTreeIndices.empty())) {
1518715186
assert((!TE->UserTreeIndices.empty() ||
1518815187
(TE->getOpcode() == Instruction::Load && !TE->isGather())) &&
@@ -15754,8 +15753,8 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,
1575415753
return EI.UserTE == VectorizableTree.front().get() &&
1575515754
EI.EdgeIdx == UINT_MAX;
1575615755
})) &&
15757-
!(GatheredLoadsEntriesFirst != NoGatheredLoads &&
15758-
IE->Idx >= GatheredLoadsEntriesFirst &&
15756+
!(GatheredLoadsEntriesFirst.has_value() &&
15757+
IE->Idx >= *GatheredLoadsEntriesFirst &&
1575915758
VectorizableTree.front()->isGather() &&
1576015759
is_contained(VectorizableTree.front()->Scalars, I)))
1576115760
continue;
@@ -16969,8 +16968,7 @@ void BoUpSLP::computeMinimumValueSizes() {
1696916968
(NodeIdx == 0 && !VectorizableTree[NodeIdx]->UserTreeIndices.empty()) ||
1697016969
(NodeIdx != 0 && any_of(VectorizableTree[NodeIdx]->UserTreeIndices,
1697116970
[NodeIdx](const EdgeInfo &EI) {
16972-
return EI.UserTE->Idx >
16973-
static_cast<int>(NodeIdx);
16971+
return EI.UserTE->Idx > NodeIdx;
1697416972
})))
1697516973
return;
1697616974

0 commit comments

Comments
 (0)