-
Notifications
You must be signed in to change notification settings - Fork 14.3k
SLPVectorizer: Avoid looking at uselists of constants #134578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SLPVectorizer: Avoid looking at uselists of constants #134578
Conversation
This is an unproductive use of compile time
@llvm/pr-subscribers-vectorizers @llvm/pr-subscribers-llvm-transforms Author: Matt Arsenault (arsenm) ChangesThis is an unproductive use of compile time Full diff: https://github.com/llvm/llvm-project/pull/134578.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 31c684e16f051..94c0289807245 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6273,7 +6273,7 @@ BoUpSLP::getReorderingData(const TreeEntry &TE, bool TopToBottom,
SmallVector<Instruction *> UserBVHead(TE.Scalars.size());
for (auto [I, V] : zip(UserBVHead, TE.Scalars)) {
- if (!V->hasNUsesOrMore(1))
+ if (isa<Constant>(V) || !V->hasNUsesOrMore(1))
continue;
auto *II = dyn_cast<InsertElementInst>(*V->user_begin());
if (!II)
@@ -13433,7 +13433,7 @@ bool BoUpSLP::isTreeTinyAndNotFullyVectorizable(bool ForReduction) const {
allSameBlock(VectorizableTree.front()->Scalars));
if (any_of(VectorizableTree, [&](const std::unique_ptr<TreeEntry> &TE) {
return TE->isGather() && all_of(TE->Scalars, [&](Value *V) {
- return isa<ExtractElementInst, UndefValue>(V) ||
+ return isa<ExtractElementInst, Constant>(V) ||
(IsAllowedSingleBVNode &&
!V->hasNUsesOrMore(UsesLimit) &&
any_of(V->users(), IsaPred<InsertElementInst>));
@@ -19459,7 +19459,7 @@ bool BoUpSLP::collectValuesToDemote(
return FinalAnalysis();
if (any_of(E.Scalars, [&](Value *V) {
- return !all_of(V->users(), [=](User *U) {
+ return !isa<Constant>(V) && !all_of(V->users(), [=](User *U) {
return isVectorized(U) ||
(E.Idx == 0 && UserIgnoreList &&
UserIgnoreList->contains(U)) ||
|
We're seeing Clang crashes after this commit. The same setup didn't cause any problems before, and I verified that this only started happening after 65c7ea7. The crash is happening in very specific circumstances, which are not trivial to reproduce and reason about, so I fully realize that the problem may be elsewhere, and this commit is just a trigger. The way I can consistently reproduce the crash is:
So far I figured out that changing the set of inputs used in step 3 can make the crash disappear. The crash stack trace looks like this:
|
After a bit more investigation I found out that the only thing this commit affects is the instrumented profile, which then leads to the crash even when compiling clang from sources before this commit. So the problem is in the SLP vectorizer, but not in this change. Looking further... |
I managed to gather a line annotated stack trace:
@alexey-bataev could you take a look at this? Upd: I bisected this error to 19aec00, the follow-up fix 076318b doesn't help here. |
Need a reproducer, the crash occurs on push_back to SmallVector and cannot understand why without reproducer |
Currently it looks like some memory corruption problem |
As I mentioned, the reproducer is tricky here. I haven't yet figured out how to build a clang that would reliably crash on the inputs I have without the specific profiles gathered from our code. I'm still working on this though. |
I'm looking at the crash, seems like a codegenprepare issue |
To close the loop: the details of the problem are in #138208 (unrelated to SLPVectorizer). |
This is an unproductive use of compile time