[llvm] fcaf290 - [SLP]Fix PR52756: SLPVectorizer crashes with assertion VecTy == FinalVecTy.
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 20 05:39:58 PST 2021
Author: Alexey Bataev
Date: 2021-12-20T05:15:01-08:00
New Revision: fcaf290d0278bb83387e1a1d972c55e08b8c40e3
URL: https://github.com/llvm/llvm-project/commit/fcaf290d0278bb83387e1a1d972c55e08b8c40e3
DIFF: https://github.com/llvm/llvm-project/commit/fcaf290d0278bb83387e1a1d972c55e08b8c40e3.diff
LOG: [SLP]Fix PR52756: SLPVectorizer crashes with assertion VecTy == FinalVecTy.
Need to check for the number of the unique non-constant values since the
unique values may include several constants.
Differential Revision: https://reviews.llvm.org/D115939
Added:
llvm/test/Transforms/SLPVectorizer/X86/reused-undefs.ll
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index cbcdcc3cf325b..08fec6dca0bc5 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3568,8 +3568,11 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
} else {
LLVM_DEBUG(dbgs() << "SLP: Shuffle for reused scalars.\n");
if (NumUniqueScalarValues <= 1 ||
- (NumUniqueScalarValues == 2 &&
- any_of(UniqueValues, UndefValue::classof)) ||
+ (UniquePositions.size() == 1 && all_of(UniqueValues,
+ [](Value *V) {
+ return isa<UndefValue>(V) ||
+ !isConstant(V);
+ })) ||
!llvm::isPowerOf2_32(NumUniqueScalarValues)) {
LLVM_DEBUG(dbgs() << "SLP: Scalar used twice in bundle.\n");
newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx);
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/reused-undefs.ll b/llvm/test/Transforms/SLPVectorizer/X86/reused-undefs.ll
new file mode 100644
index 0000000000000..c587adfa9d11f
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/reused-undefs.ll
@@ -0,0 +1,40 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-1000 < %s | FileCheck %s
+
+define i32 @main(i32 %0) {
+; CHECK-LABEL: @main(
+; CHECK-NEXT: for.cond.preheader:
+; CHECK-NEXT: br i1 false, label [[FOR_END:%.*]], label [[FOR_INC_PREHEADER:%.*]]
+; CHECK: for.inc.preheader:
+; CHECK-NEXT: [[TMP1:%.*]] = insertelement <8 x i32> <i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 poison, i32 poison>, i32 [[TMP0:%.*]], i32 6
+; CHECK-NEXT: br i1 false, label [[FOR_END]], label [[L1_PREHEADER:%.*]]
+; CHECK: for.end:
+; CHECK-NEXT: [[DOTPR:%.*]] = phi i32 [ 0, [[FOR_INC_PREHEADER]] ], [ 0, [[FOR_COND_PREHEADER:%.*]] ]
+; CHECK-NEXT: [[TMP2:%.*]] = insertelement <8 x i32> poison, i32 [[DOTPR]], i32 0
+; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <8 x i32> [[TMP2]], <8 x i32> poison, <8 x i32> <i32 undef, i32 undef, i32 undef, i32 0, i32 0, i32 0, i32 0, i32 0>
+; CHECK-NEXT: br label [[L1_PREHEADER]]
+; CHECK: L1.preheader:
+; CHECK-NEXT: [[TMP3:%.*]] = phi <8 x i32> [ [[SHUFFLE]], [[FOR_END]] ], [ [[TMP1]], [[FOR_INC_PREHEADER]] ]
+; CHECK-NEXT: ret i32 0
+;
+for.cond.preheader:
+ br i1 false, label %for.end, label %for.inc.preheader
+
+for.inc.preheader:
+ br i1 false, label %for.end, label %L1.preheader
+
+for.end:
+ %.pr = phi i32 [ 0, %for.inc.preheader ], [ 0, %for.cond.preheader ]
+ br label %L1.preheader
+
+L1.preheader:
+ %1 = phi i32 [ %.pr, %for.end ], [ %0, %for.inc.preheader ]
+ %2 = phi i32 [ %.pr, %for.end ], [ 0, %for.inc.preheader ]
+ %3 = phi i32 [ %.pr, %for.end ], [ 0, %for.inc.preheader ]
+ %4 = phi i32 [ %.pr, %for.end ], [ undef, %for.inc.preheader ]
+ %j.2.ph1 = phi i32 [ %.pr, %for.end ], [ 0, %for.inc.preheader ]
+ %k.0.ph = phi i32 [ undef, %for.end ], [ 0, %for.inc.preheader ]
+ %o.1.ph = phi i32 [ undef, %for.end ], [ 0, %for.inc.preheader ]
+ %n.1.ph = phi i32 [ undef, %for.end ], [ 0, %for.inc.preheader ]
+ ret i32 0
+}
More information about the llvm-commits
mailing list