Skip to content

Commit 8122bb9

Browse files
committed
[SLP]Fix a check for non-schedulable instructions
Need to fix a check for non-schedulable instructions in getLastInstructionInBundle function, because this check may not work correctly during the codegen. Instead, need to check that actually these instructions were never scheduled, since the scheduling analysis always performed before the codegen and is stable. Fixes #132841
1 parent 822aa5e commit 8122bb9

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15071,7 +15071,18 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
1507115071

1507215072
// Set the insert point to the beginning of the basic block if the entry
1507315073
// should not be scheduled.
15074-
if (doesNotNeedToSchedule(E->Scalars) ||
15074+
const auto *It = BlocksSchedules.find(BB);
15075+
auto IsNotScheduledEntry = [&](const TreeEntry *E) {
15076+
if (E->isGather())
15077+
return false;
15078+
// Found previously that the instruction do not need to be scheduled.
15079+
return It == BlocksSchedules.end() || all_of(E->Scalars, [&](Value *V) {
15080+
if (!isa<Instruction>(V))
15081+
return true;
15082+
return It->second->getScheduleBundles(V).empty();
15083+
});
15084+
};
15085+
if (IsNotScheduledEntry(E) ||
1507515086
(!E->isGather() && all_of(E->Scalars, isVectorLikeInstWithConstOps))) {
1507615087
if ((E->getOpcode() == Instruction::GetElementPtr &&
1507715088
any_of(E->Scalars,
@@ -15098,12 +15109,11 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
1509815109
// scheduled, and the last instruction is VL.back(). So we start with
1509915110
// VL.back() and iterate over schedule data until we reach the end of the
1510015111
// bundle. The end of the bundle is marked by null ScheduleData.
15101-
if (BlocksSchedules.count(BB) && !E->isGather()) {
15112+
if (It != BlocksSchedules.end() && !E->isGather()) {
1510215113
Value *V = E->isOneOf(E->Scalars.back());
1510315114
if (doesNotNeedToBeScheduled(V))
1510415115
V = *find_if_not(E->Scalars, doesNotNeedToBeScheduled);
15105-
if (ArrayRef<ScheduleBundle *> Bundles =
15106-
BlocksSchedules[BB]->getScheduleBundles(V);
15116+
if (ArrayRef<ScheduleBundle *> Bundles = It->second->getScheduleBundles(V);
1510715117
!Bundles.empty()) {
1510815118
const auto *It = find_if(
1510915119
Bundles, [&](ScheduleBundle *B) { return B->getTreeEntry() == E; });
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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-unknown -mcpu=znver2 < %s | FileCheck %s
3+
4+
define void @test() {
5+
; CHECK-LABEL: define void @test(
6+
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
7+
; CHECK-NEXT: [[ENTRY:.*:]]
8+
; CHECK-NEXT: br label %[[BB1:.*]]
9+
; CHECK: [[IF_THEN_I_I:.*]]:
10+
; CHECK-NEXT: br label %[[BB5:.*]]
11+
; CHECK: [[BB1]]:
12+
; CHECK-NEXT: [[TMP0:%.*]] = zext i1 false to i64
13+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i64> <i64 poison, i64 0>, i64 [[TMP0]], i32 0
14+
; CHECK-NEXT: [[TMP2:%.*]] = add <2 x i64> zeroinitializer, [[TMP1]]
15+
; CHECK-NEXT: [[TMP3:%.*]] = call <4 x i64> @llvm.vector.insert.v4i64.v2i64(<4 x i64> <i64 0, i64 0, i64 poison, i64 poison>, <2 x i64> [[TMP2]], i64 2)
16+
; CHECK-NEXT: [[TMP4:%.*]] = call <4 x i64> @llvm.vector.insert.v4i64.v2i64(<4 x i64> <i64 0, i64 0, i64 poison, i64 poison>, <2 x i64> [[TMP2]], i64 2)
17+
; CHECK-NEXT: br i1 false, label %[[BB5]], label %[[BB2:.*]]
18+
; CHECK: [[BB5]]:
19+
; CHECK-NEXT: [[TMP6:%.*]] = phi <4 x i64> [ [[TMP3]], %[[BB1]] ], [ poison, %[[IF_THEN_I_I]] ]
20+
; CHECK-NEXT: br label %[[BB2]]
21+
; CHECK: [[BB2]]:
22+
; CHECK-NEXT: [[TMP7:%.*]] = phi <4 x i64> [ [[TMP6]], %[[BB5]] ], [ [[TMP4]], %[[BB1]] ]
23+
; CHECK-NEXT: store <4 x i64> [[TMP7]], ptr getelementptr inbounds nuw (i8, ptr null, i64 40), align 8
24+
; CHECK-NEXT: ret void
25+
;
26+
entry:
27+
br label %bb1
28+
29+
if.then.i.i:
30+
br label %3
31+
32+
bb1:
33+
%0 = zext i1 false to i64
34+
%1 = add i64 0, %0
35+
%2 = add i64 0, 0
36+
br i1 false, label %3, label %bb2
37+
38+
3:
39+
%pgocount51962 = phi i64 [ 0, %bb1 ], [ 0, %if.then.i.i ]
40+
%pgocount62360 = phi i64 [ 0, %bb1 ], [ 0, %if.then.i.i ]
41+
%pgocount83056 = phi i64 [ %1, %bb1 ], [ 0, %if.then.i.i ]
42+
%pgocount93354 = phi i64 [ %2, %bb1 ], [ 0, %if.then.i.i ]
43+
br label %bb2
44+
45+
bb2:
46+
%pgocount51961 = phi i64 [ %pgocount51962, %3 ], [ 0, %bb1 ]
47+
%pgocount62359 = phi i64 [ %pgocount62360, %3 ], [ 0, %bb1 ]
48+
%pgocount83055 = phi i64 [ %pgocount83056, %3 ], [ %1, %bb1 ]
49+
%pgocount93353 = phi i64 [ %pgocount93354, %3 ], [ %2, %bb1 ]
50+
store i64 %pgocount51961, ptr getelementptr inbounds nuw (i8, ptr null, i64 40), align 8
51+
store i64 %pgocount62359, ptr getelementptr inbounds nuw (i8, ptr null, i64 48), align 8
52+
store i64 %pgocount83055, ptr getelementptr inbounds nuw (i8, ptr null, i64 56), align 8
53+
store i64 %pgocount93353, ptr getelementptr inbounds nuw (i8, ptr null, i64 64), align 8
54+
ret void
55+
}

0 commit comments

Comments
 (0)