[llvm] 76f0ff8 - [SLP]Add an extra check to avoid infinite vectorization attempts
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 25 14:30:28 PST 2024
Author: Alexey Bataev
Date: 2024-11-25T14:27:44-08:00
New Revision: 76f0ff8210d56a050d2679926a2fdddd3a8c16d6
URL: https://github.com/llvm/llvm-project/commit/76f0ff8210d56a050d2679926a2fdddd3a8c16d6
DIFF: https://github.com/llvm/llvm-project/commit/76f0ff8210d56a050d2679926a2fdddd3a8c16d6.diff
LOG: [SLP]Add an extra check to avoid infinite vectorization attempts
Added extra check for the cost of the buildvector if the -slp-threshold
option is used. Prevents infinite vectorization attempts.
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/X86/buildvector-schedule-for-subvector.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 34b80c1e360815..115cbd4d2ce5e4 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -12034,7 +12034,14 @@ bool BoUpSLP::isTreeTinyAndNotFullyVectorizable(bool ForReduction) const {
if (VectorizableTree.back()->isGather() &&
VectorizableTree.back()->isAltShuffle() &&
VectorizableTree.back()->getVectorFactor() > 2 &&
- allSameBlock(VectorizableTree.back()->Scalars))
+ allSameBlock(VectorizableTree.back()->Scalars) &&
+ !VectorizableTree.back()->Scalars.front()->getType()->isVectorTy() &&
+ TTI->getScalarizationOverhead(
+ getWidenedType(VectorizableTree.back()->Scalars.front()->getType(),
+ VectorizableTree.back()->getVectorFactor()),
+ APInt::getAllOnes(VectorizableTree.back()->getVectorFactor()),
+ /*Insert=*/true, /*Extract=*/false,
+ TTI::TCK_RecipThroughput) > -SLPCostThreshold)
return false;
// Otherwise, we can't vectorize the tree. It is both tiny and not fully
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/buildvector-schedule-for-subvector.ll b/llvm/test/Transforms/SLPVectorizer/X86/buildvector-schedule-for-subvector.ll
index a0b390011faa6f..3bf13b76a93327 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/buildvector-schedule-for-subvector.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/buildvector-schedule-for-subvector.ll
@@ -7,7 +7,7 @@ define void @test() {
; CHECK-NEXT: [[ADD:%.*]] = add i32 1, 0
; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x i32> <i32 0, i32 0, i32 0, i32 poison>, i32 [[ADD]], i32 3
; CHECK-NEXT: [[TMP1:%.*]] = icmp samesign ult <4 x i32> [[TMP0]], zeroinitializer
-; CHECK-NEXT: [[ICMP:%.*]] = icmp samesign ult i32 0, 0
+; CHECK-NEXT: [[ICMP:%.*]] = extractelement <4 x i1> [[TMP1]], i32 2
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[ICMP]], i32 0, i32 0
; CHECK-NEXT: [[ZEXT:%.*]] = zext i32 [[SELECT]] to i64
; CHECK-NEXT: [[GETELEMENTPTR:%.*]] = getelementptr ptr addrspace(1), ptr addrspace(1) null, i64 [[ZEXT]]
@@ -16,8 +16,6 @@ define void @test() {
; CHECK-NEXT: [[CALL:%.*]] = call i32 null(<2 x double> zeroinitializer)
; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x i32> <i32 0, i32 0, i32 0, i32 poison>, i32 [[CALL]], i32 3
; CHECK-NEXT: [[TMP3:%.*]] = icmp eq <4 x i32> [[TMP2]], zeroinitializer
-; CHECK-NEXT: [[TMP4:%.*]] = call <8 x i1> @llvm.vector.insert.v8i1.v4i1(<8 x i1> poison, <4 x i1> [[TMP3]], i64 0)
-; CHECK-NEXT: [[TMP5:%.*]] = call <8 x i1> @llvm.vector.insert.v8i1.v4i1(<8 x i1> [[TMP4]], <4 x i1> [[TMP1]], i64 4)
; CHECK-NEXT: ret void
;
bb:
More information about the llvm-commits
mailing list