Skip to content

Commit c3e1633

Browse files
authored
[SLP][REVEC] Ignore UserTreeIndex if it is empty. (llvm#131993)
Previously, the all_of check did not consider the case where the TreeEntry is empty (i.e., when it is the first entry).
1 parent 6003c30 commit c3e1633

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -6455,14 +6455,11 @@ void BoUpSLP::reorderTopToBottom() {
64556455
assert(SLPReVec && "Only supported by REVEC.");
64566456
// ShuffleVectorInst does not do reorderOperands (and it should not
64576457
// because ShuffleVectorInst supports only a limited set of
6458-
// patterns). Only do reorderNodeWithReuses if all of the users are
6459-
// not ShuffleVectorInst.
6460-
if (isa<ShuffleVectorInst>(TE->UserTreeIndex.UserTE->getMainOp()))
6458+
// patterns). Only do reorderNodeWithReuses if the user is not
6459+
// ShuffleVectorInst.
6460+
if (TE->UserTreeIndex && TE->UserTreeIndex.UserTE->hasState() &&
6461+
isa<ShuffleVectorInst>(TE->UserTreeIndex.UserTE->getMainOp()))
64616462
continue;
6462-
assert((!TE->UserTreeIndex ||
6463-
!isa<ShuffleVectorInst>(
6464-
TE->UserTreeIndex.UserTE->getMainOp())) &&
6465-
"Does not know how to reorder.");
64666463
}
64676464
// Update ordering of the operands with the smaller VF than the given
64686465
// one.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 < %s -mtriple=x86_64-unknown-linux-gnu -slp-revec | FileCheck %s
3+
4+
define void @test() {
5+
; CHECK-LABEL: define void @test() {
6+
; CHECK-NEXT: [[BB:.*]]:
7+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i64 0 to i32
8+
; CHECK-NEXT: br label %[[BB1:.*]]
9+
; CHECK: [[BB1]]:
10+
; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x i32> [ zeroinitializer, %[[BB]] ], [ [[TMP4:%.*]], %[[BB1]] ]
11+
; CHECK-NEXT: [[TMP1:%.*]] = extractelement <2 x i32> [[TMP0]], i32 1
12+
; CHECK-NEXT: [[TMP2:%.*]] = call i8 @llvm.vector.reduce.mul.v4i8(<4 x i8> zeroinitializer)
13+
; CHECK-NEXT: [[TMP3:%.*]] = zext i8 [[TMP2]] to i32
14+
; CHECK-NEXT: [[OP_RDX:%.*]] = mul i32 [[TMP3]], [[TMP1]]
15+
; CHECK-NEXT: [[OP_RDX1:%.*]] = mul i32 [[OP_RDX]], [[TRUNC]]
16+
; CHECK-NEXT: [[TMP4]] = insertelement <2 x i32> <i32 0, i32 poison>, i32 [[OP_RDX1]], i32 1
17+
; CHECK-NEXT: br label %[[BB1]]
18+
;
19+
bb:
20+
br label %bb1
21+
22+
bb1:
23+
%phi = phi i32 [ 0, %bb ], [ %mul9, %bb1 ]
24+
%phi2 = phi i32 [ 0, %bb ], [ 0, %bb1 ]
25+
%trunc = trunc i64 0 to i32
26+
%mul = mul i32 0, %trunc
27+
%mul3 = mul i32 %trunc, %phi
28+
%mul4 = mul i32 %mul3, %mul
29+
%mul5 = mul i32 %mul4, %mul
30+
%trunc6 = trunc i64 0 to i32
31+
%mul7 = mul i32 0, %trunc6
32+
%mul8 = mul i32 %mul5, %mul7
33+
%mul9 = mul i32 %mul8, %mul7
34+
br label %bb1
35+
}

0 commit comments

Comments
 (0)