Skip to content

Commit c601928

Browse files
committed
[SLP][NFC]Improve compile time by storing all nodes for the given
scalar. No need to scan the whole graph when trying to find matching node for the scalar, vectorized in several nodes, better to store corresponding nodes along and scan just this small list.
1 parent 65c053d commit c601928

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

+14-12
Original file line numberDiff line numberDiff line change
@@ -2918,7 +2918,7 @@ class BoUpSLP {
29182918
"Scalar already in tree!");
29192919
if (TE) {
29202920
if (TE != Last)
2921-
MultiNodeScalars.insert(V);
2921+
MultiNodeScalars.try_emplace(V).first->getSecond().push_back(Last);
29222922
continue;
29232923
}
29242924
ScalarToTreeEntry[V] = Last;
@@ -2979,8 +2979,9 @@ class BoUpSLP {
29792979
/// Maps a specific scalar to its tree entry.
29802980
SmallDenseMap<Value *, TreeEntry *> ScalarToTreeEntry;
29812981

2982-
/// List of scalars, used in several vectorize nodes.
2983-
SmallDenseSet<Value *> MultiNodeScalars;
2982+
/// List of scalars, used in several vectorize nodes, and the list of the
2983+
/// nodes.
2984+
SmallDenseMap<Value *, SmallVector<TreeEntry *>> MultiNodeScalars;
29842985

29852986
/// Maps a value to the proposed vectorizable size.
29862987
SmallDenseMap<Value *, unsigned> InstrElementSize;
@@ -9866,15 +9867,16 @@ Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx) {
98669867
};
98679868
TreeEntry *VE = getTreeEntry(S.OpValue);
98689869
bool IsSameVE = VE && CheckSameVE(VE);
9869-
if (!IsSameVE && MultiNodeScalars.contains(S.OpValue)) {
9870-
auto *I =
9871-
find_if(VectorizableTree, [&](const std::unique_ptr<TreeEntry> &TE) {
9872-
return TE->State != TreeEntry::NeedToGather && TE.get() != VE &&
9873-
CheckSameVE(TE.get());
9874-
});
9875-
if (I != VectorizableTree.end()) {
9876-
VE = I->get();
9877-
IsSameVE = true;
9870+
if (!IsSameVE) {
9871+
auto It = MultiNodeScalars.find(S.OpValue);
9872+
if (It != MultiNodeScalars.end()) {
9873+
auto *I = find_if(It->getSecond(), [&](const TreeEntry *TE) {
9874+
return TE != VE && CheckSameVE(TE);
9875+
});
9876+
if (I != It->getSecond().end()) {
9877+
VE = *I;
9878+
IsSameVE = true;
9879+
}
98789880
}
98799881
}
98809882
if (IsSameVE) {

0 commit comments

Comments
 (0)