Skip to content

Commit 18ef467

Browse files
committed
[SLP]Fix PR108709: postpone buildvector clustered nodes, if required
The "clustered" nodes for buildvector nodes must be postponed in accordance with the global flag, otherwise it may cause crash because of the dependency between phi nodes.
1 parent 69f3244 commit 18ef467

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,7 +2883,8 @@ class BoUpSLP {
28832883
/// Create a new vector from a list of scalar values. Produces a sequence
28842884
/// which exploits values reused across lanes, and arranges the inserts
28852885
/// for ease of later optimization.
2886-
Value *createBuildVector(const TreeEntry *E, Type *ScalarTy);
2886+
Value *createBuildVector(const TreeEntry *E, Type *ScalarTy,
2887+
bool PostponedPHIs);
28872888

28882889
/// Returns the instruction in the bundle, which can be used as a base point
28892890
/// for scheduling. Usually it is the last instruction in the bundle, except
@@ -13198,9 +13199,10 @@ ResTy BoUpSLP::processBuildVector(const TreeEntry *E, Type *ScalarTy,
1319813199
return Res;
1319913200
}
1320013201

13201-
Value *BoUpSLP::createBuildVector(const TreeEntry *E, Type *ScalarTy) {
13202+
Value *BoUpSLP::createBuildVector(const TreeEntry *E, Type *ScalarTy,
13203+
bool PostponedPHIs) {
1320213204
for (auto [EIdx, _] : E->CombinedEntriesWithIndices)
13203-
(void)vectorizeTree(VectorizableTree[EIdx].get(), /*PostponedPHIs=*/false);
13205+
(void)vectorizeTree(VectorizableTree[EIdx].get(), PostponedPHIs);
1320413206
return processBuildVector<ShuffleInstructionBuilder, Value *>(E, ScalarTy,
1320513207
Builder, *this);
1320613208
}
@@ -13231,7 +13233,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
1323113233
// Set insert point for non-reduction initial nodes.
1323213234
if (E->getMainOp() && E->Idx == 0 && !UserIgnoreList)
1323313235
setInsertPointAfterBundle(E);
13234-
Value *Vec = createBuildVector(E, ScalarTy);
13236+
Value *Vec = createBuildVector(E, ScalarTy, PostponedPHIs);
1323513237
E->VectorizedValue = Vec;
1323613238
return Vec;
1323713239
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S --passes=slp-vectorizer -slp-threshold=-99999 -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
3+
4+
define void @test() {
5+
; CHECK-LABEL: define void @test() {
6+
; CHECK-NEXT: [[BB:.*]]:
7+
; CHECK-NEXT: br label %[[BB6:.*]]
8+
; CHECK: [[BB1:.*]]:
9+
; CHECK-NEXT: br label %[[BB2:.*]]
10+
; CHECK: [[BB2]]:
11+
; CHECK-NEXT: [[TMP0:%.*]] = phi <4 x i32> [ poison, %[[BB1]] ], [ [[TMP5:%.*]], %[[BB6]] ]
12+
; CHECK-NEXT: ret void
13+
; CHECK: [[BB6]]:
14+
; CHECK-NEXT: [[TMP1:%.*]] = phi <2 x i32> [ zeroinitializer, %[[BB]] ], [ [[TMP8:%.*]], %[[BB6]] ]
15+
; CHECK-NEXT: [[TMP2:%.*]] = call <4 x i32> @llvm.vector.insert.v4i32.v2i32(<4 x i32> <i32 0, i32 0, i32 poison, i32 poison>, <2 x i32> [[TMP1]], i64 2)
16+
; CHECK-NEXT: [[TMP3:%.*]] = ashr <4 x i32> zeroinitializer, [[TMP2]]
17+
; CHECK-NEXT: [[TMP4:%.*]] = mul <4 x i32> zeroinitializer, [[TMP2]]
18+
; CHECK-NEXT: [[TMP5]] = shufflevector <4 x i32> [[TMP3]], <4 x i32> [[TMP4]], <4 x i32> <i32 0, i32 5, i32 6, i32 7>
19+
; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <4 x i32> [[TMP2]], <4 x i32> poison, <2 x i32> <i32 2, i32 poison>
20+
; CHECK-NEXT: [[TMP7:%.*]] = shufflevector <2 x i32> [[TMP6]], <2 x i32> <i32 poison, i32 0>, <2 x i32> <i32 0, i32 3>
21+
; CHECK-NEXT: [[TMP8]] = mul <2 x i32> zeroinitializer, [[TMP7]]
22+
; CHECK-NEXT: br i1 false, label %[[BB2]], label %[[BB6]]
23+
;
24+
bb:
25+
br label %bb6
26+
27+
bb1:
28+
%ashr = ashr i32 0, 0
29+
br label %bb2
30+
31+
bb2:
32+
%phi = phi i32 [ %ashr, %bb1 ], [ %ashr9, %bb6 ]
33+
%phi3 = phi i32 [ 0, %bb1 ], [ %mul10, %bb6 ]
34+
%phi4 = phi i32 [ 0, %bb1 ], [ %mul11, %bb6 ]
35+
%phi5 = phi i32 [ 0, %bb1 ], [ %mul, %bb6 ]
36+
ret void
37+
38+
bb6:
39+
%phi7 = phi i32 [ 0, %bb ], [ %mul11, %bb6 ]
40+
%phi8 = phi i32 [ 0, %bb ], [ %mul10, %bb6 ]
41+
%mul = mul i32 0, %phi8
42+
%ashr9 = ashr i32 0, 0
43+
%mul10 = mul i32 0, 0
44+
%mul11 = mul i32 %phi7, 0
45+
br i1 false, label %bb2, label %bb6
46+
}

0 commit comments

Comments
 (0)