[llvm] d4cec1c - [SLP][NFCI]Improve compile time by using SmallBitVector and filtering
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 14 06:29:47 PST 2023
Author: Alexey Bataev
Date: 2023-11-14T06:27:17-08:00
New Revision: d4cec1ce7313608670d5a97d7c9fcccad68ac659
URL: https://github.com/llvm/llvm-project/commit/d4cec1ce7313608670d5a97d7c9fcccad68ac659
DIFF: https://github.com/llvm/llvm-project/commit/d4cec1ce7313608670d5a97d7c9fcccad68ac659.diff
LOG: [SLP][NFCI]Improve compile time by using SmallBitVector and filtering
trees with phis/buildvectors only.
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index bb233ed7d6c77ce..bf380d073e635bb 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -4166,7 +4166,8 @@ static bool areTwoInsertFromSameBuildVector(
// Go through the vector operand of insertelement instructions trying to find
// either VU as the original vector for IE2 or V as the original vector for
// IE1.
- SmallSet<int, 8> ReusedIdx;
+ SmallBitVector ReusedIdx(
+ cast<VectorType>(VU->getType())->getElementCount().getKnownMinValue());
bool IsReusedIdx = false;
do {
if (IE2 == VU && !IE1)
@@ -4174,16 +4175,18 @@ static bool areTwoInsertFromSameBuildVector(
if (IE1 == V && !IE2)
return V->hasOneUse();
if (IE1 && IE1 != V) {
- IsReusedIdx |=
- !ReusedIdx.insert(getInsertIndex(IE1).value_or(*Idx2)).second;
+ unsigned Idx1 = getInsertIndex(IE1).value_or(*Idx2);
+ IsReusedIdx |= ReusedIdx.test(Idx1);
+ ReusedIdx.set(Idx1);
if ((IE1 != VU && !IE1->hasOneUse()) || IsReusedIdx)
IE1 = nullptr;
else
IE1 = dyn_cast_or_null<InsertElementInst>(GetBaseOperand(IE1));
}
if (IE2 && IE2 != VU) {
- IsReusedIdx |=
- !ReusedIdx.insert(getInsertIndex(IE2).value_or(*Idx1)).second;
+ unsigned Idx2 = getInsertIndex(IE2).value_or(*Idx1);
+ IsReusedIdx |= ReusedIdx.test(Idx2);
+ ReusedIdx.set(Idx2);
if ((IE2 != V && !IE2->hasOneUse()) || IsReusedIdx)
IE2 = nullptr;
else
@@ -8630,6 +8633,23 @@ bool BoUpSLP::isTreeTinyAndNotFullyVectorizable(bool ForReduction) const {
allConstant(VectorizableTree[1]->Scalars))))
return true;
+ // If the graph includes only PHI nodes and gathers, it is defnitely not
+ // profitable for the vectorization, we can skip it, if the cost threshold is
+ // default. The cost of vectorized PHI nodes is almost always 0 + the cost of
+ // gathers/buildvectors.
+ constexpr unsigned Limit = 4;
+ if (!ForReduction && !SLPCostThreshold.getNumOccurrences() &&
+ !VectorizableTree.empty() &&
+ all_of(VectorizableTree, [&](const std::unique_ptr<TreeEntry> &TE) {
+ return (TE->State == TreeEntry::NeedToGather &&
+ TE->getOpcode() != Instruction::ExtractElement &&
+ count_if(TE->Scalars,
+ [](Value *V) { return isa<ExtractElementInst>(V); }) <=
+ Limit) ||
+ TE->getOpcode() == Instruction::PHI;
+ }))
+ return true;
+
// We can vectorize the tree if its size is greater than or equal to the
// minimum size specified by the MinTreeSize command line option.
if (VectorizableTree.size() >= MinTreeSize)
More information about the llvm-commits
mailing list