| Issue |
180458
|
| Summary |
[SLP] Infinite loop when using negative slp-threshold with zero-cost InsertElement
|
| Labels |
llvm:SLPVectorizer
|
| Assignees |
alexey-bataev
|
| Reporter |
arcbbb
|
The SLP vectorizer hangs in an infinite loop when:
1. A negative -slp-threshold value is specified (e.g., -slp-threshold=-5)
2. The vectorization cost for an InsertElement tree is exactly 0
3. The vectorized result produces a similar InsertElement pattern that is again vectorizable with cost 0
Reduced reproducer below (note: this only triggers the issue with the downstream TTI cost model).
```
define void @TEST__MAIN.for.body312(ptr %call) {
newFuncRoot:
br label %for.body312
for.body312: ; preds = %for.body312, %newFuncRoot
%indvars.iv.next2451.5 = add i64 0, 6
%0 = trunc i64 %indvars.iv.next2451.5 to i32
%rem.6 = and i32 %0, 3
%conv.6 = uitofp i32 %rem.6 to double
%arrayidx314.6 = getelementptr double, ptr %call, i64 %indvars.iv.next2451.5
store double %conv.6, ptr %arrayidx314.6, align 8
%indvars.iv.next2451.6 = add i64 0, 7
%1 = trunc i64 %indvars.iv.next2451.6 to i32
%rem.7 = and i32 %1, 3
%conv.7 = uitofp i32 %rem.7 to double
%arrayidx314.7 = getelementptr double, ptr %call, i64 %indvars.iv.next2451.6
store double %conv.7, ptr %arrayidx314.7, align 8
br label %for.body312
}
```
Here's a potential workaround:
```
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index b5a7b833da1b..29bf069d88fd 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -17391,6 +17391,12 @@ InstructionCost BoUpSLP::getTreeCost(InstructionCost TreeCost,
}))
return InstructionCost::getInvalid();
+ // Buildvector with zero cost and negative threshold should not be vectorized,
+ // as it might produce similar insertelement pattern and cause infinite loop.
+ if (SLPCostThreshold < 0 && Cost == 0 &&
+ isa<InsertElementInst>(VectorizableTree[0]->Scalars[0]))
+ return InstructionCost::getInvalid();
+
Cost += ExtractCost;
auto &&ResizeToVF = [this, &Cost](const TreeEntry *TE, ArrayRef<int> Mask,
bool ForSingleMask) {
```
Any thoughts on this?
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs