[llvm] ead9d6a - [SLP]Check VectorizableTree is not empty before accessing elements
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 17 11:07:38 PDT 2025
Author: Alexey Bataev
Date: 2025-03-17T11:04:38-07:00
New Revision: ead9d6a56d764190aa916c5259ab50986f803128
URL: https://github.com/llvm/llvm-project/commit/ead9d6a56d764190aa916c5259ab50986f803128
DIFF: https://github.com/llvm/llvm-project/commit/ead9d6a56d764190aa916c5259ab50986f803128.diff
LOG: [SLP]Check VectorizableTree is not empty before accessing elements
Need to check VectorizableTree is not empty before accessing elements.
Fixes #131635
Added:
llvm/test/Transforms/SLPVectorizer/X86/empty-vectorizable-tree.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 d450336cbc3ce..e5902299c842c 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -8893,7 +8893,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
TTI.getArithmeticInstrCost(Opcode1, Op2VecTy, Kind);
InstructionCost NewCost =
NewVecOpsCost + InsertCost +
- (VectorizableTree.front()->hasState() &&
+ (!VectorizableTree.empty() && VectorizableTree.front()->hasState() &&
VectorizableTree.front()->getOpcode() == Instruction::Store
? NewShuffleCost
: 0);
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/empty-vectorizable-tree.ll b/llvm/test/Transforms/SLPVectorizer/X86/empty-vectorizable-tree.ll
new file mode 100644
index 0000000000000..d7ccaa0f5c0e2
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/empty-vectorizable-tree.ll
@@ -0,0 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mcpu=core-avx2 < %s | FileCheck %s
+
+%struct.1 = type { [258 x [1 x i32]], [56 x i8], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [2 x [16 x [1 x i32]]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [10 x [16 x [1 x i32]]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [2 x [1 x i32]], [56 x i8], [2 x [1 x i32]], [56 x i8], [2 x [1 x i32]], [56 x i8] }
+
+define <8 x float> @foo(i32 %0, i32 %1, i32 %2) {
+; CHECK-LABEL: define <8 x float> @foo(
+; CHECK-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]], i32 [[TMP2:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[VECEXT_I615:%.*]] = extractelement <4 x i32> zeroinitializer, i64 0
+; CHECK-NEXT: [[IDX_EXT:%.*]] = sext i32 [[VECEXT_I615]] to i64
+; CHECK-NEXT: [[__U_I613:%.*]] = getelementptr i8, ptr getelementptr inbounds ([[STRUCT_1:%.*]], ptr null, i64 -35, i32 37, i64 0, i64 0), i64 [[IDX_EXT]]
+; CHECK-NEXT: [[IDX_EXT320:%.*]] = sext i32 [[TMP0]] to i64
+; CHECK-NEXT: [[__U_I611:%.*]] = getelementptr i8, ptr getelementptr inbounds ([[STRUCT_1]], ptr null, i64 -35, i32 37, i64 0, i64 0), i64 [[IDX_EXT320]]
+; CHECK-NEXT: [[IDX_EXT326:%.*]] = sext i32 [[TMP1]] to i64
+; CHECK-NEXT: [[__U_I609:%.*]] = getelementptr i8, ptr getelementptr inbounds ([[STRUCT_1]], ptr null, i64 -35, i32 37, i64 0, i64 0), i64 [[IDX_EXT326]]
+; CHECK-NEXT: [[IDX_EXT332:%.*]] = sext i32 [[TMP2]] to i64
+; CHECK-NEXT: [[__U_I607:%.*]] = getelementptr i8, ptr getelementptr inbounds ([[STRUCT_1]], ptr null, i64 -35, i32 37, i64 0, i64 0), i64 [[IDX_EXT332]]
+; CHECK-NEXT: [[IDX_EXT338:%.*]] = zext i32 [[TMP2]] to i64
+; CHECK-NEXT: [[__U_I605:%.*]] = getelementptr i8, ptr getelementptr inbounds ([[STRUCT_1]], ptr null, i64 -35, i32 37, i64 0, i64 0), i64 [[IDX_EXT338]]
+; CHECK-NEXT: [[IDX_EXT344:%.*]] = zext i32 [[TMP1]] to i64
+; CHECK-NEXT: [[__U_I603:%.*]] = getelementptr i8, ptr getelementptr inbounds ([[STRUCT_1]], ptr null, i64 -35, i32 37, i64 0, i64 0), i64 [[IDX_EXT344]]
+; CHECK-NEXT: [[IDX_EXT350:%.*]] = zext i32 0 to i64
+; CHECK-NEXT: [[__U_I601:%.*]] = getelementptr i8, ptr getelementptr inbounds ([[STRUCT_1]], ptr null, i64 -35, i32 37, i64 0, i64 0), i64 [[IDX_EXT350]]
+; CHECK-NEXT: [[IDX_EXT356:%.*]] = zext i32 [[TMP0]] to i64
+; CHECK-NEXT: [[__U_I:%.*]] = getelementptr i8, ptr getelementptr inbounds ([[STRUCT_1]], ptr null, i64 -35, i32 37, i64 0, i64 0), i64 [[IDX_EXT356]]
+; CHECK-NEXT: ret <8 x float> zeroinitializer
+;
+entry:
+ %vecext.i615 = extractelement <4 x i32> zeroinitializer, i64 0
+ %idx.ext = sext i32 %vecext.i615 to i64
+ %__u.i613 = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext
+ %idx.ext320 = sext i32 %0 to i64
+ %__u.i611 = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext320
+ %idx.ext326 = sext i32 %1 to i64
+ %__u.i609 = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext326
+ %idx.ext332 = sext i32 %2 to i64
+ %__u.i607 = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext332
+ %idx.ext338 = zext i32 %2 to i64
+ %__u.i605 = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext338
+ %idx.ext344 = zext i32 %1 to i64
+ %__u.i603 = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext344
+ %idx.ext350 = zext i32 0 to i64
+ %__u.i601 = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext350
+ %idx.ext356 = zext i32 %0 to i64
+ %__u.i = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext356
+ ret <8 x float> zeroinitializer
+}
More information about the llvm-commits
mailing list