[llvm] c0e5e7d - [SLP]Fix a crash trying finding insert point for GEP nodes with non-gep
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Thu May 4 09:45:19 PDT 2023
Author: Alexey Bataev
Date: 2023-05-04T09:43:37-07:00
New Revision: c0e5e7db9ae27db765981f5e55e0819f369d7095
URL: https://github.com/llvm/llvm-project/commit/c0e5e7db9ae27db765981f5e55e0819f369d7095
DIFF: https://github.com/llvm/llvm-project/commit/c0e5e7db9ae27db765981f5e55e0819f369d7095.diff
LOG: [SLP]Fix a crash trying finding insert point for GEP nodes with non-gep
insts.
If the vectorizable GEP node is built, which should not be scheduled,
and at least one node is a non-gep instruction, need to insert the
vectorized instructions before the last instruction in the list, not
before the first one, otherwise the instructions may be emitted in the
wrong order.
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/X86/gep-nodes-with-non-gep-inst.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 1081f1303d727..9b20a0c431a21 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -8951,9 +8951,11 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
LastInst = I;
continue;
}
- assert(isVectorLikeInstWithConstOps(LastInst) &&
- isVectorLikeInstWithConstOps(I) &&
- "Expected vector-like insts only.");
+ assert(((E->getOpcode() == Instruction::GetElementPtr &&
+ !isa<GetElementPtrInst>(I)) ||
+ (isVectorLikeInstWithConstOps(LastInst) &&
+ isVectorLikeInstWithConstOps(I))) &&
+ "Expected vector-like or non-GEP in GEP node insts only.");
if (!DT->isReachableFromEntry(LastInst->getParent())) {
LastInst = I;
continue;
@@ -9015,7 +9017,12 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
(doesNotNeedToSchedule(E->Scalars) ||
all_of(E->Scalars, isVectorLikeInstWithConstOps))) {
Instruction *InsertInst;
- if (all_of(E->Scalars, [](Value *V) {
+ if ((E->getOpcode() == Instruction::GetElementPtr &&
+ any_of(E->Scalars,
+ [](Value *V) {
+ return !isa<GetElementPtrInst>(V) && isa<Instruction>(V);
+ })) ||
+ all_of(E->Scalars, [](Value *V) {
return !isVectorLikeInstWithConstOps(V) && isUsedOutsideBlock(V);
}))
InsertInst = FindLastInst();
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/gep-nodes-with-non-gep-inst.ll b/llvm/test/Transforms/SLPVectorizer/X86/gep-nodes-with-non-gep-inst.ll
index 22789f6061226..9e43cefef2801 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/gep-nodes-with-non-gep-inst.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/gep-nodes-with-non-gep-inst.ll
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
; RUN: opt -passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mcpu=skx -S < %s | FileCheck %s
+; RUN: opt -passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mcpu=skx -S < %s -slp-threshold=-100 | FileCheck %s --check-prefix=CHECK-SLP-THRESHOLD
define void @test() {
; CHECK-LABEL: define void @test
@@ -21,6 +22,19 @@ define void @test() {
; CHECK-NEXT: [[BV_3:%.*]] = icmp eq i64 [[V_3]], 0
; CHECK-NEXT: ret void
;
+; CHECK-SLP-THRESHOLD-LABEL: define void @test
+; CHECK-SLP-THRESHOLD-SAME: () #[[ATTR0:[0-9]+]] {
+; CHECK-SLP-THRESHOLD-NEXT: entry:
+; CHECK-SLP-THRESHOLD-NEXT: [[COND_IN_V:%.*]] = select i1 false, ptr null, ptr null
+; CHECK-SLP-THRESHOLD-NEXT: br label [[BB:%.*]]
+; CHECK-SLP-THRESHOLD: bb:
+; CHECK-SLP-THRESHOLD-NEXT: [[TMP0:%.*]] = insertelement <4 x ptr> poison, ptr [[COND_IN_V]], i32 0
+; CHECK-SLP-THRESHOLD-NEXT: [[TMP1:%.*]] = shufflevector <4 x ptr> [[TMP0]], <4 x ptr> poison, <4 x i32> zeroinitializer
+; CHECK-SLP-THRESHOLD-NEXT: [[TMP2:%.*]] = getelementptr i64, <4 x ptr> [[TMP1]], <4 x i64> <i64 12, i64 8, i64 4, i64 0>
+; CHECK-SLP-THRESHOLD-NEXT: [[TMP3:%.*]] = call <4 x i64> @llvm.masked.gather.v4i64.v4p0(<4 x ptr> [[TMP2]], i32 8, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x i64> poison)
+; CHECK-SLP-THRESHOLD-NEXT: [[TMP4:%.*]] = icmp eq <4 x i64> [[TMP3]], zeroinitializer
+; CHECK-SLP-THRESHOLD-NEXT: ret void
+;
entry:
%cond.in.v = select i1 false, ptr null, ptr null
br label %bb
More information about the llvm-commits
mailing list