Skip to content

Commit 9b40896

Browse files
committed
[SLP][NFC]Use has_single_bit instead of isPowerOf2 functions, NFC.
1 parent fd36a7b commit 9b40896

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,7 +2448,7 @@ class BoUpSLP {
24482448
}
24492449
// TODO: Check if we can remove a check for non-power-2 number of
24502450
// scalars after full support of non-power-2 vectorization.
2451-
return UniqueValues.size() != 2 && isPowerOf2_32(UniqueValues.size());
2451+
return UniqueValues.size() != 2 && has_single_bit(UniqueValues.size());
24522452
};
24532453

24542454
// If the initial strategy fails for any of the operand indexes, then we
@@ -3240,7 +3240,7 @@ class BoUpSLP {
32403240

32413241
/// Return true if this is a non-power-of-2 node.
32423242
bool isNonPowOf2Vec() const {
3243-
bool IsNonPowerOf2 = !isPowerOf2_32(Scalars.size());
3243+
bool IsNonPowerOf2 = !has_single_bit(Scalars.size());
32443244
assert((!IsNonPowerOf2 || ReuseShuffleIndices.empty()) &&
32453245
"Reshuffling not supported with non-power-of-2 vectors yet.");
32463246
return IsNonPowerOf2;
@@ -4696,7 +4696,7 @@ BoUpSLP::LoadsState BoUpSLP::canVectorizeLoads(
46964696
// Check the order of pointer operands or that all pointers are the same.
46974697
bool IsSorted = sortPtrAccesses(PointerOps, ScalarTy, *DL, *SE, Order);
46984698
// FIXME: Reordering isn't implemented for non-power-of-2 nodes yet.
4699-
if (!Order.empty() && !isPowerOf2_32(VL.size())) {
4699+
if (!Order.empty() && !has_single_bit(VL.size())) {
47004700
assert(VectorizeNonPowerOf2 && "non-power-of-2 number of loads only "
47014701
"supported with VectorizeNonPowerOf2");
47024702
return LoadsState::Gather;
@@ -4746,13 +4746,14 @@ BoUpSLP::LoadsState BoUpSLP::canVectorizeLoads(
47464746
return !getTreeEntry(U) && !MustGather.contains(U);
47474747
});
47484748
});
4749-
if (IsPossibleStrided && (IsAnyPointerUsedOutGraph ||
4750-
((Sz > MinProfitableStridedLoads ||
4751-
(static_cast<unsigned>(std::abs(*Diff)) <=
4752-
MaxProfitableLoadStride * Sz &&
4753-
isPowerOf2_32(std::abs(*Diff)))) &&
4754-
static_cast<unsigned>(std::abs(*Diff)) > Sz) ||
4755-
*Diff == -(static_cast<int>(Sz) - 1))) {
4749+
const unsigned AbsoluteDiff = std::abs(*Diff);
4750+
if (IsPossibleStrided &&
4751+
(IsAnyPointerUsedOutGraph ||
4752+
((Sz > MinProfitableStridedLoads ||
4753+
(AbsoluteDiff <= MaxProfitableLoadStride * Sz &&
4754+
has_single_bit(AbsoluteDiff))) &&
4755+
AbsoluteDiff > Sz) ||
4756+
*Diff == -(static_cast<int>(Sz) - 1))) {
47564757
int Stride = *Diff / static_cast<int>(Sz - 1);
47574758
if (*Diff == Stride * static_cast<int>(Sz - 1)) {
47584759
Align Alignment =
@@ -6495,7 +6496,7 @@ BoUpSLP::TreeEntry::EntryState BoUpSLP::getScalarsVectorizationState(
64956496
case Instruction::ExtractElement: {
64966497
bool Reuse = canReuseExtract(VL, VL0, CurrentOrder);
64976498
// FIXME: Vectorizing is not supported yet for non-power-of-2 ops.
6498-
if (!isPowerOf2_32(VL.size()))
6499+
if (!has_single_bit(VL.size()))
64996500
return TreeEntry::NeedToGather;
65006501
if (Reuse || !CurrentOrder.empty())
65016502
return TreeEntry::Vectorize;
@@ -10907,7 +10908,7 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) {
1090710908
// Keep original scalar if number of externally used instructions in
1090810909
// the same entry is not power of 2. It may help to do some extra
1090910910
// vectorization for now.
10910-
KeepScalar = ScalarUsesCount <= 1 || !isPowerOf2_32(ScalarUsesCount);
10911+
KeepScalar = ScalarUsesCount <= 1 || !has_single_bit(ScalarUsesCount);
1091110912
}
1091210913
if (KeepScalar) {
1091310914
ExternalUsesAsOriginalScalar.insert(EU.Scalar);
@@ -16353,7 +16354,7 @@ SLPVectorizerPass::vectorizeStoreChain(ArrayRef<Value *> Chain, BoUpSLP &R,
1635316354
const unsigned Sz = R.getVectorElementSize(Chain[0]);
1635416355
unsigned VF = Chain.size();
1635516356

16356-
if (!isPowerOf2_32(Sz) || !isPowerOf2_32(VF) || VF < 2 || VF < MinVF) {
16357+
if (!has_single_bit(Sz) || !has_single_bit(VF) || VF < 2 || VF < MinVF) {
1635716358
// Check if vectorizing with a non-power-of-2 VF should be considered. At
1635816359
// the moment, only consider cases where VF + 1 is a power-of-2, i.e. almost
1635916360
// all vector lanes are used.
@@ -16372,8 +16373,8 @@ SLPVectorizerPass::vectorizeStoreChain(ArrayRef<Value *> Chain, BoUpSLP &R,
1637216373
if (all_of(ValOps, IsaPred<Instruction>) && ValOps.size() > 1) {
1637316374
DenseSet<Value *> Stores(Chain.begin(), Chain.end());
1637416375
bool IsPowerOf2 =
16375-
isPowerOf2_32(ValOps.size()) ||
16376-
(VectorizeNonPowerOf2 && isPowerOf2_32(ValOps.size() + 1));
16376+
has_single_bit(ValOps.size()) ||
16377+
(VectorizeNonPowerOf2 && has_single_bit(ValOps.size() + 1));
1637716378
if ((!IsPowerOf2 && S.getOpcode() && S.getOpcode() != Instruction::Load &&
1637816379
(!S.MainOp->isSafeToRemove() ||
1637916380
any_of(ValOps.getArrayRef(),
@@ -16540,7 +16541,7 @@ bool SLPVectorizerPass::vectorizeStores(
1654016541
// consider cases where VF + 1 is a power-of-2, i.e. almost all vector
1654116542
// lanes are used.
1654216543
unsigned CandVF = Operands.size();
16543-
if (isPowerOf2_32(CandVF + 1) && CandVF <= MaxRegVF)
16544+
if (has_single_bit(CandVF + 1) && CandVF <= MaxRegVF)
1654416545
NonPowerOf2VF = CandVF;
1654516546
}
1654616547

@@ -16946,7 +16947,7 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
1694616947
for (unsigned I = NextInst; I < MaxInst; ++I) {
1694716948
unsigned ActualVF = std::min(MaxInst - I, VF);
1694816949

16949-
if (!isPowerOf2_32(ActualVF))
16950+
if (!has_single_bit(ActualVF))
1695016951
continue;
1695116952

1695216953
if (MaxVFOnly && ActualVF < MaxVF)
@@ -18292,7 +18293,7 @@ class HorizontalReduction {
1829218293
Value *emitReduction(Value *VectorizedValue, IRBuilderBase &Builder,
1829318294
unsigned ReduxWidth, const TargetTransformInfo *TTI) {
1829418295
assert(VectorizedValue && "Need to have a vectorized tree node");
18295-
assert(isPowerOf2_32(ReduxWidth) &&
18296+
assert(has_single_bit(ReduxWidth) &&
1829618297
"We only handle power-of-two reductions for now");
1829718298
assert(RdxKind != RecurKind::FMulAdd &&
1829818299
"A call to the llvm.fmuladd intrinsic is not handled yet");

0 commit comments

Comments
 (0)