Skip to content

Commit fedd72b

Browse files
alexey-bataevgithub-actions[bot]
authored andcommitted
Automerge: [SLP]Fix a crash for buildvector nodes with parent phi nodes with same incoming blocks
If trying to find matching buildvector node for another nodes, and both nodes are used by vectorized phi nodes and are coming from the same parent block, this nodes should be considered matched to avoid a crash.
2 parents 71cb575 + 1182be5 commit fedd72b

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13585,6 +13585,15 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(
1358513585
UserPHI ? UserPHI->getIncomingBlock(UseEI.EdgeIdx)->getTerminator()
1358613586
: &getLastInstructionInBundle(UseEI.UserTE);
1358713587
if (TEInsertPt == InsertPt) {
13588+
// If the users are the PHI nodes with the same incoming blocks - skip.
13589+
if (TEUseEI.UserTE->State == TreeEntry::Vectorize &&
13590+
TEUseEI.UserTE->getOpcode() == Instruction::PHI &&
13591+
UseEI.UserTE->State == TreeEntry::Vectorize &&
13592+
UseEI.UserTE->getOpcode() == Instruction::PHI &&
13593+
TEUseEI.UserTE != UseEI.UserTE &&
13594+
TEUseEI.UserTE->getMainOp()->getParent() ==
13595+
UseEI.UserTE->getMainOp()->getParent())
13596+
continue;
1358813597
// If 2 gathers are operands of the same entry (regardless of whether
1358913598
// user is PHI or else), compare operands indices, use the earlier one
1359013599
// as the base.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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-generic-linux-gnu -mattr=+avx < %s | FileCheck %s
3+
4+
define void @test(ptr %0, float %1) {
5+
; CHECK-LABEL: define void @test(
6+
; CHECK-SAME: ptr [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0:[0-9]+]] {
7+
; CHECK-NEXT: [[TMP3:%.*]] = load float, ptr [[TMP0]], align 4
8+
; CHECK-NEXT: [[TMP4:%.*]] = insertelement <2 x float> <float 0.000000e+00, float poison>, float [[TMP3]], i32 1
9+
; CHECK-NEXT: [[TMP5:%.*]] = insertelement <4 x float> <float poison, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00>, float [[TMP3]], i32 0
10+
; CHECK-NEXT: [[TMP6:%.*]] = insertelement <2 x float> poison, float [[TMP1]], i32 0
11+
; CHECK-NEXT: [[TMP7:%.*]] = shufflevector <2 x float> [[TMP6]], <2 x float> poison, <2 x i32> zeroinitializer
12+
; CHECK-NEXT: br label %[[BB8:.*]]
13+
; CHECK: [[BB8]]:
14+
; CHECK-NEXT: [[TMP9:%.*]] = phi <4 x float> [ [[TMP15:%.*]], %[[BB8]] ], [ [[TMP5]], [[TMP2:%.*]] ]
15+
; CHECK-NEXT: [[TMP10:%.*]] = phi <2 x float> [ [[TMP7]], %[[BB8]] ], [ [[TMP4]], [[TMP2]] ]
16+
; CHECK-NEXT: [[TMP11:%.*]] = shufflevector <2 x float> [[TMP10]], <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 0>
17+
; CHECK-NEXT: [[TMP12:%.*]] = fmul <4 x float> [[TMP9]], zeroinitializer
18+
; CHECK-NEXT: [[TMP13:%.*]] = fadd <4 x float> [[TMP12]], zeroinitializer
19+
; CHECK-NEXT: store <4 x float> [[TMP13]], ptr [[TMP0]], align 16
20+
; CHECK-NEXT: [[TMP14:%.*]] = fmul <4 x float> [[TMP11]], zeroinitializer
21+
; CHECK-NEXT: [[TMP15]] = fadd <4 x float> [[TMP14]], zeroinitializer
22+
; CHECK-NEXT: br label %[[BB8]]
23+
;
24+
%3 = load float, ptr %0, align 4
25+
br label %4
26+
27+
4:
28+
%5 = phi float [ %1, %4 ], [ %3, %2 ]
29+
%6 = phi float [ %1, %4 ], [ 0.000000e+00, %2 ]
30+
%7 = phi float [ %28, %4 ], [ 0.000000e+00, %2 ]
31+
%8 = phi float [ %26, %4 ], [ 0.000000e+00, %2 ]
32+
%9 = phi float [ %26, %4 ], [ %3, %2 ]
33+
%10 = phi float [ %24, %4 ], [ 0.000000e+00, %2 ]
34+
%11 = fmul float %9, 0.000000e+00
35+
%12 = fadd float %11, 0.000000e+00
36+
%13 = fmul float %7, 0.000000e+00
37+
%14 = fadd float %13, 0.000000e+00
38+
%15 = fmul float %10, 0.000000e+00
39+
%16 = fadd float %15, 0.000000e+00
40+
%17 = fmul float %8, 0.000000e+00
41+
%18 = fadd float %17, 0.000000e+00
42+
%19 = insertelement <4 x float> zeroinitializer, float %12, i64 0
43+
%20 = insertelement <4 x float> %19, float %14, i64 1
44+
%21 = insertelement <4 x float> %20, float %16, i64 2
45+
%22 = insertelement <4 x float> %21, float %18, i64 3
46+
store <4 x float> %22, ptr %0, align 16
47+
%23 = fmul float %6, 0.000000e+00
48+
%24 = fadd float %23, 0.000000e+00
49+
%25 = fmul float %6, 0.000000e+00
50+
%26 = fadd float %25, 0.000000e+00
51+
%27 = fmul float %5, 0.000000e+00
52+
%28 = fadd float %27, 0.000000e+00
53+
br label %4
54+
}

0 commit comments

Comments
 (0)