Skip to content

Commit 605a9f5

Browse files
committed
[SLP]Check if user node is same as other node and check operand order
Need to check if the user node is same as other node and check operand order to prevent a compiler crash when trying to find matching gather node with user nodes, having the same last instruction. Fixes #131195
1 parent 8413f4d commit 605a9f5

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14081,6 +14081,17 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(
1408114081
}
1408214082
return true;
1408314083
};
14084+
auto CheckParentNodes = [&](const TreeEntry *User1, const TreeEntry *User2,
14085+
unsigned EdgeIdx) {
14086+
const TreeEntry *Ptr1 = User1;
14087+
while (Ptr1) {
14088+
unsigned Idx = Ptr1->UserTreeIndex.EdgeIdx;
14089+
Ptr1 = Ptr1->UserTreeIndex.UserTE;
14090+
if (Ptr1 == User2)
14091+
return Idx < EdgeIdx;
14092+
}
14093+
return false;
14094+
};
1408414095
for (Value *V : VL) {
1408514096
if (isConstant(V) || !VisitedValue.insert(V).second)
1408614097
continue;
@@ -14121,6 +14132,9 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(
1412114132
(TEUseEI.UserTE->Idx < UseEI.UserTE->Idx ||
1412214133
HasGatherUser(TEUseEI.UserTE)))
1412314134
continue;
14135+
// If the user node is the operand of the other user node - skip.
14136+
if (CheckParentNodes(TEUseEI.UserTE, UseEI.UserTE, UseEI.EdgeIdx))
14137+
continue;
1412414138
}
1412514139

1412614140
// Check if the user node of the TE comes after user node of TEPtr,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 @wombat(i32 %arg) {
5+
; CHECK-LABEL: define void @wombat(
6+
; CHECK-SAME: i32 [[ARG:%.*]]) {
7+
; CHECK-NEXT: [[BB:.*:]]
8+
; CHECK-NEXT: br label %[[BB1:.*]]
9+
; CHECK: [[BB1]]:
10+
; CHECK-NEXT: br i1 false, label %[[BB2:.*]], label %[[BB5:.*]]
11+
; CHECK: [[BB2]]:
12+
; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x i32> [ [[TMP4:%.*]], %[[BB4:.*]] ], [ zeroinitializer, %[[BB1]] ]
13+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> <i32 poison, i32 1>, i32 [[ARG]], i32 0
14+
; CHECK-NEXT: [[TMP2:%.*]] = sub <2 x i32> [[TMP0]], [[TMP1]]
15+
; CHECK-NEXT: [[TMP3:%.*]] = or <2 x i32> [[TMP0]], [[TMP1]]
16+
; CHECK-NEXT: [[TMP4]] = shufflevector <2 x i32> [[TMP2]], <2 x i32> [[TMP3]], <2 x i32> <i32 0, i32 3>
17+
; CHECK-NEXT: [[TMP5:%.*]] = insertelement <2 x i32> <i32 poison, i32 0>, i32 [[ARG]], i32 0
18+
; CHECK-NEXT: [[TMP6:%.*]] = sub <2 x i32> [[TMP0]], [[TMP5]]
19+
; CHECK-NEXT: [[TMP7:%.*]] = and <2 x i32> [[TMP0]], [[TMP5]]
20+
; CHECK-NEXT: [[TMP8:%.*]] = shufflevector <2 x i32> [[TMP6]], <2 x i32> [[TMP7]], <2 x i32> <i32 0, i32 3>
21+
; CHECK-NEXT: br label %[[BB4]]
22+
; CHECK: [[BB4]]:
23+
; CHECK-NEXT: br i1 false, label %[[BB2]], label %[[BB5]]
24+
; CHECK: [[BB5]]:
25+
; CHECK-NEXT: [[TMP9:%.*]] = phi <2 x i32> [ zeroinitializer, %[[BB1]] ], [ [[TMP8]], %[[BB4]] ]
26+
; CHECK-NEXT: ret void
27+
;
28+
bb:
29+
br label %bb1
30+
31+
bb1:
32+
br i1 false, label %bb2, label %bb5
33+
34+
bb2:
35+
%phi = phi i32 [ %or, %bb4 ], [ 0, %bb1 ]
36+
%phi3 = phi i32 [ %sub, %bb4 ], [ 0, %bb1 ]
37+
%or = or i32 %phi, 1
38+
%and = and i32 0, %phi
39+
%sub = sub i32 %phi3, %arg
40+
br label %bb4
41+
42+
bb4:
43+
br i1 false, label %bb2, label %bb5
44+
45+
bb5:
46+
%phi6 = phi i32 [ 0, %bb1 ], [ %and, %bb4 ]
47+
%phi7 = phi i32 [ 0, %bb1 ], [ %sub, %bb4 ]
48+
ret void
49+
}

0 commit comments

Comments
 (0)