Skip to content

Commit dda2a5d

Browse files
committed
[SLP][NFC] Rename a couple of variables and replace an if-else with an std::min
- Rename `LimitForRegisterSize` to `MaxVFOnly` to make the meaning of the limit less ambiguous - Rename `OpsWidth` to `ActualVF`, which makes it clear that this is the VF we are using for vectorization. - Replace the if-else code for the initialization of OpsWidth with an std::min. Differential Revision: https://reviews.llvm.org/D150241
1 parent 689715f commit dda2a5d

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ struct SLPVectorizerPass : public PassInfoMixin<SLPVectorizerPass> {
9595
bool tryToVectorizePair(Value *A, Value *B, slpvectorizer::BoUpSLP &R);
9696

9797
/// Try to vectorize a list of operands.
98-
/// \param LimitForRegisterSize Vectorize only using maximal allowed register
99-
/// size.
98+
/// \param MaxVFOnly Vectorize only using maximal allowed register size.
10099
/// \returns true if a value was vectorized.
101100
bool tryToVectorizeList(ArrayRef<Value *> VL, slpvectorizer::BoUpSLP &R,
102-
bool LimitForRegisterSize = false);
101+
bool MaxVFOnly = false);
103102

104103
/// Try to vectorize a chain that may start at the operands of \p I.
105104
bool tryToVectorize(Instruction *I, slpvectorizer::BoUpSLP &R);

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12380,7 +12380,7 @@ bool SLPVectorizerPass::tryToVectorizePair(Value *A, Value *B, BoUpSLP &R) {
1238012380
}
1238112381

1238212382
bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
12383-
bool LimitForRegisterSize) {
12383+
bool MaxVFOnly) {
1238412384
if (VL.size() < 2)
1238512385
return false;
1238612386

@@ -12442,29 +12442,25 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
1244212442
if (TTI->getNumberOfParts(VecTy) == VF)
1244312443
continue;
1244412444
for (unsigned I = NextInst; I < MaxInst; ++I) {
12445-
unsigned OpsWidth = 0;
12445+
unsigned ActualVF = std::min(MaxInst - I, VF);
1244612446

12447-
if (I + VF > MaxInst)
12448-
OpsWidth = MaxInst - I;
12449-
else
12450-
OpsWidth = VF;
12451-
12452-
if (!isPowerOf2_32(OpsWidth))
12447+
if (!isPowerOf2_32(ActualVF))
1245312448
continue;
1245412449

12455-
if ((LimitForRegisterSize && OpsWidth < MaxVF) ||
12456-
(VF > MinVF && OpsWidth <= VF / 2) || (VF == MinVF && OpsWidth < 2))
12450+
if (MaxVFOnly && ActualVF < MaxVF)
12451+
break;
12452+
if ((VF > MinVF && ActualVF <= VF / 2) || (VF == MinVF && ActualVF < 2))
1245712453
break;
1245812454

12459-
ArrayRef<Value *> Ops = VL.slice(I, OpsWidth);
12455+
ArrayRef<Value *> Ops = VL.slice(I, ActualVF);
1246012456
// Check that a previous iteration of this loop did not delete the Value.
1246112457
if (llvm::any_of(Ops, [&R](Value *V) {
1246212458
auto *I = dyn_cast<Instruction>(V);
1246312459
return I && R.isDeleted(I);
1246412460
}))
1246512461
continue;
1246612462

12467-
LLVM_DEBUG(dbgs() << "SLP: Analyzing " << OpsWidth << " operations "
12463+
LLVM_DEBUG(dbgs() << "SLP: Analyzing " << ActualVF << " operations "
1246812464
<< "\n");
1246912465

1247012466
R.buildTree(Ops);
@@ -12482,7 +12478,7 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
1248212478
MinCost = std::min(MinCost, Cost);
1248312479

1248412480
LLVM_DEBUG(dbgs() << "SLP: Found cost = " << Cost
12485-
<< " for VF=" << OpsWidth << "\n");
12481+
<< " for VF=" << ActualVF << "\n");
1248612482
if (Cost < -SLPCostThreshold) {
1248712483
LLVM_DEBUG(dbgs() << "SLP: Vectorizing list at cost:" << Cost << ".\n");
1248812484
R.getORE()->emit(OptimizationRemark(SV_NAME, "VectorizedList",
@@ -14277,7 +14273,7 @@ static bool tryToVectorizeSequence(
1427714273
SmallVectorImpl<T *> &Incoming, function_ref<bool(T *, T *)> Comparator,
1427814274
function_ref<bool(T *, T *)> AreCompatible,
1427914275
function_ref<bool(ArrayRef<T *>, bool)> TryToVectorizeHelper,
14280-
bool LimitForRegisterSize, BoUpSLP &R) {
14276+
bool MaxVFOnly, BoUpSLP &R) {
1428114277
bool Changed = false;
1428214278
// Sort by type, parent, operands.
1428314279
stable_sort(Incoming, Comparator);
@@ -14305,7 +14301,7 @@ static bool tryToVectorizeSequence(
1430514301
// same/alternate ops only, this may result in some extra final
1430614302
// vectorization.
1430714303
if (NumElts > 1 &&
14308-
TryToVectorizeHelper(ArrayRef(IncIt, NumElts), LimitForRegisterSize)) {
14304+
TryToVectorizeHelper(ArrayRef(IncIt, NumElts), MaxVFOnly)) {
1430914305
// Success start over because instructions might have been changed.
1431014306
Changed = true;
1431114307
} else {
@@ -14324,20 +14320,19 @@ static bool tryToVectorizeSequence(
1432414320
// Final attempt to vectorize instructions with the same types.
1432514321
if (Candidates.size() > 1 &&
1432614322
(SameTypeIt == E || (*SameTypeIt)->getType() != (*IncIt)->getType())) {
14327-
if (TryToVectorizeHelper(Candidates, /*LimitForRegisterSize=*/false)) {
14323+
if (TryToVectorizeHelper(Candidates, /*MaxVFOnly=*/false)) {
1432814324
// Success start over because instructions might have been changed.
1432914325
Changed = true;
14330-
} else if (LimitForRegisterSize) {
14326+
} else if (MaxVFOnly) {
1433114327
// Try to vectorize using small vectors.
1433214328
for (auto *It = Candidates.begin(), *End = Candidates.end();
1433314329
It != End;) {
1433414330
auto *SameTypeIt = It;
1433514331
while (SameTypeIt != End && AreCompatible(*SameTypeIt, *It))
1433614332
++SameTypeIt;
1433714333
unsigned NumElts = (SameTypeIt - It);
14338-
if (NumElts > 1 &&
14339-
TryToVectorizeHelper(ArrayRef(It, NumElts),
14340-
/*LimitForRegisterSize=*/false))
14334+
if (NumElts > 1 && TryToVectorizeHelper(ArrayRef(It, NumElts),
14335+
/*MaxVFOnly=*/false))
1434114336
Changed = true;
1434214337
It = SameTypeIt;
1434314338
}
@@ -14438,7 +14433,7 @@ bool SLPVectorizerPass::vectorizeCmpInsts(ArrayRef<CmpInst *> CmpInsts,
1443814433
SmallVector<Value *> Vals(CmpInsts.begin(), CmpInsts.end());
1443914434
Changed |= tryToVectorizeSequence<Value>(
1444014435
Vals, CompareSorter, AreCompatibleCompares,
14441-
[this, &R](ArrayRef<Value *> Candidates, bool LimitForRegisterSize) {
14436+
[this, &R](ArrayRef<Value *> Candidates, bool MaxVFOnly) {
1444214437
// Exclude possible reductions from other blocks.
1444314438
bool ArePossiblyReducedInOtherBlock = any_of(Candidates, [](Value *V) {
1444414439
return any_of(V->users(), [V](User *U) {
@@ -14449,9 +14444,9 @@ bool SLPVectorizerPass::vectorizeCmpInsts(ArrayRef<CmpInst *> CmpInsts,
1444914444
});
1445014445
if (ArePossiblyReducedInOtherBlock)
1445114446
return false;
14452-
return tryToVectorizeList(Candidates, R, LimitForRegisterSize);
14447+
return tryToVectorizeList(Candidates, R, MaxVFOnly);
1445314448
},
14454-
/*LimitForRegisterSize=*/true, R);
14449+
/*MaxVFOnly=*/true, R);
1445514450
return Changed;
1445614451
}
1445714452

@@ -14635,10 +14630,10 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
1463514630

1463614631
HaveVectorizedPhiNodes = tryToVectorizeSequence<Value>(
1463714632
Incoming, PHICompare, AreCompatiblePHIs,
14638-
[this, &R](ArrayRef<Value *> Candidates, bool LimitForRegisterSize) {
14639-
return tryToVectorizeList(Candidates, R, LimitForRegisterSize);
14633+
[this, &R](ArrayRef<Value *> Candidates, bool MaxVFOnly) {
14634+
return tryToVectorizeList(Candidates, R, MaxVFOnly);
1464014635
},
14641-
/*LimitForRegisterSize=*/true, R);
14636+
/*MaxVFOnly=*/true, R);
1464214637
Changed |= HaveVectorizedPhiNodes;
1464314638
VisitedInstrs.insert(Incoming.begin(), Incoming.end());
1464414639
} while (HaveVectorizedPhiNodes);
@@ -14931,7 +14926,7 @@ bool SLPVectorizerPass::vectorizeStoreChains(BoUpSLP &R) {
1493114926
[this, &R](ArrayRef<StoreInst *> Candidates, bool) {
1493214927
return vectorizeStores(Candidates, R);
1493314928
},
14934-
/*LimitForRegisterSize=*/false, R);
14929+
/*MaxVFOnly=*/false, R);
1493514930
}
1493614931
return Changed;
1493714932
}

0 commit comments

Comments
 (0)