Skip to content

Commit 77bec78

Browse files
committed
[SLP]Do not look for last instruction in schedule block for buildvectors
If looking for the insertion point for the node and the node is a buildvector node, the compiler should not use scheduling info for such nodes, they may contain only partial info, which is not fully correct and may cause compiler crash. Fixes llvm#114082
1 parent 0f04043 commit 77bec78

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13398,7 +13398,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
1339813398
// scheduled, and the last instruction is VL.back(). So we start with
1339913399
// VL.back() and iterate over schedule data until we reach the end of the
1340013400
// bundle. The end of the bundle is marked by null ScheduleData.
13401-
if (BlocksSchedules.count(BB)) {
13401+
if (BlocksSchedules.count(BB) && !E->isGather()) {
1340213402
Value *V = E->isOneOf(E->Scalars.back());
1340313403
if (doesNotNeedToBeScheduled(V))
1340413404
V = *find_if_not(E->Scalars, doesNotNeedToBeScheduled);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-99999 < %s | FileCheck %s
3+
4+
define void @test() {
5+
; CHECK-LABEL: define void @test() {
6+
; CHECK-NEXT: [[BB:.*:]]
7+
; CHECK-NEXT: [[ADD:%.*]] = add i32 1, 0
8+
; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x i32> <i32 0, i32 0, i32 0, i32 poison>, i32 [[ADD]], i32 3
9+
; CHECK-NEXT: [[TMP1:%.*]] = icmp samesign ult <4 x i32> [[TMP0]], zeroinitializer
10+
; CHECK-NEXT: [[ICMP:%.*]] = icmp samesign ult i32 0, 0
11+
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[ICMP]], i32 0, i32 0
12+
; CHECK-NEXT: [[ZEXT:%.*]] = zext i32 [[SELECT]] to i64
13+
; CHECK-NEXT: [[GETELEMENTPTR:%.*]] = getelementptr ptr addrspace(1), ptr addrspace(1) null, i64 [[ZEXT]]
14+
; CHECK-NEXT: store ptr addrspace(1) null, ptr addrspace(1) [[GETELEMENTPTR]], align 8
15+
; CHECK-NEXT: store volatile i32 0, ptr addrspace(1) null, align 4
16+
; CHECK-NEXT: [[CALL:%.*]] = call i32 null(<2 x double> zeroinitializer)
17+
; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x i32> <i32 0, i32 0, i32 0, i32 poison>, i32 [[CALL]], i32 3
18+
; CHECK-NEXT: [[TMP3:%.*]] = icmp eq <4 x i32> [[TMP2]], zeroinitializer
19+
; CHECK-NEXT: [[TMP4:%.*]] = call <8 x i1> @llvm.vector.insert.v8i1.v4i1(<8 x i1> poison, <4 x i1> [[TMP3]], i64 0)
20+
; CHECK-NEXT: [[TMP5:%.*]] = call <8 x i1> @llvm.vector.insert.v8i1.v4i1(<8 x i1> [[TMP4]], <4 x i1> [[TMP1]], i64 4)
21+
; CHECK-NEXT: ret void
22+
;
23+
bb:
24+
%icmp = icmp samesign ult i32 0, 0
25+
%select = select i1 %icmp, i32 0, i32 0
26+
%zext = zext i32 %select to i64
27+
%getelementptr = getelementptr ptr addrspace(1), ptr addrspace(1) null, i64 %zext
28+
store ptr addrspace(1) null, ptr addrspace(1) %getelementptr, align 8
29+
%icmp1 = icmp eq i32 0, 0
30+
%icmp2 = icmp eq i32 0, 0
31+
%icmp3 = icmp samesign ult i32 0, 0
32+
%icmp4 = icmp eq i32 0, 0
33+
%add = add i32 1, 0
34+
%icmp5 = icmp samesign ult i32 %add, 0
35+
store volatile i32 0, ptr addrspace(1) null, align 4
36+
%call = call i32 null(<2 x double> zeroinitializer)
37+
%icmp6 = icmp eq i32 %call, 0
38+
%icmp7 = icmp samesign ult i32 0, 0
39+
ret void
40+
}

0 commit comments

Comments
 (0)