Skip to content

Commit a88498f

Browse files
committed
[SLP]Skip buildvector tree, if all scalars are used externally and remain scalar
If the buildvector is going to be vector with threshold cost < 0 and all buildvector scalars are externally used and remain scalar, such a tree should not be vectorized, it may lead to a compiler hang because same scalars remain in the function and will be vectorized once again. Fixes #172609
1 parent ac6afd8 commit a88498f

File tree

2 files changed

+491
-0
lines changed

2 files changed

+491
-0
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15617,6 +15617,17 @@ bool BoUpSLP::isTreeTinyAndNotFullyVectorizable(bool ForReduction) const {
1561715617
allConstant(VectorizableTree[1]->Scalars))))
1561815618
return true;
1561915619

15620+
// Buildvector with externally used scalars, which should remain as scalars,
15621+
// should not be vectorized, the compiler may hang.
15622+
if (SLPCostThreshold < 0 && VectorizableTree.size() > 1 &&
15623+
isa<InsertElementInst>(VectorizableTree[0]->Scalars[0]) &&
15624+
VectorizableTree[1]->hasState() &&
15625+
VectorizableTree[1]->State == TreeEntry::Vectorize &&
15626+
all_of(VectorizableTree[1]->Scalars, [&](Value *V) {
15627+
return ExternalUsesAsOriginalScalar.contains(V);
15628+
}))
15629+
return true;
15630+
1562015631
// If the graph includes only PHI nodes and gathers, it is defnitely not
1562115632
// profitable for the vectorization, we can skip it, if the cost threshold is
1562215633
// default. The cost of vectorized PHI nodes is almost always 0 + the cost of

0 commit comments

Comments
 (0)