Skip to content

Commit 202137d

Browse files
committed
[SLP]Fix a crash on matching gather operands of phi nodes in loops
If the gather operands in phi nodes are matching and phi nodes may build up a loop, it may cause a compiler crash with the incorrect def-use chain. Patch fixes this crash.
1 parent 64b9410 commit 202137d

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14104,9 +14104,7 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(
1410414104
TEUseEI.UserTE->getOpcode() == Instruction::PHI &&
1410514105
UseEI.UserTE->State == TreeEntry::Vectorize &&
1410614106
UseEI.UserTE->getOpcode() == Instruction::PHI &&
14107-
TEUseEI.UserTE != UseEI.UserTE &&
14108-
TEUseEI.UserTE->getMainOp()->getParent() ==
14109-
UseEI.UserTE->getMainOp()->getParent())
14107+
TEUseEI.UserTE != UseEI.UserTE)
1411014108
continue;
1411114109
// If 2 gathers are operands of the same entry (regardless of whether
1411214110
// user is PHI or else), compare operands indices, use the earlier one

llvm/test/Transforms/SLPVectorizer/X86/delayed-gather-emission.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ define void @test() {
2929
; CHECK-NEXT: tail call void @foo(float [[MUL]])
3030
; CHECK-NEXT: [[I2:%.*]] = load float, ptr poison, align 4
3131
; CHECK-NEXT: [[TOBOOL:%.*]] = fcmp une float [[I2]], 0.000000e+00
32+
; CHECK-NEXT: [[TMP10]] = insertelement <2 x float> [[TMP2]], float [[I2]], i32 0
3233
; CHECK-NEXT: [[TMP8:%.*]] = shufflevector <2 x float> [[TMP5]], <2 x float> poison, <2 x i32> <i32 poison, i32 0>
3334
; CHECK-NEXT: [[TMP9]] = insertelement <2 x float> [[TMP8]], float [[I2]], i32 0
34-
; CHECK-NEXT: [[TMP10]] = shufflevector <2 x float> [[TMP9]], <2 x float> [[TMP2]], <2 x i32> <i32 0, i32 3>
3535
; CHECK-NEXT: br i1 [[TOBOOL]], label [[BB1]], label [[BB2]]
3636
;
3737
entry:

llvm/test/Transforms/SLPVectorizer/X86/matching-gather-nodes-phi-users.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
; YAML: Function: test
99
; YAML: Args:
1010
; YAML: - String: 'Stores SLP vectorized with cost '
11-
; YAML: - Cost: '-6'
11+
; YAML: - Cost: '-3'
1212
; YAML: - String: ' and with tree size '
1313
; YAML: - TreeSize: '16'
1414
; YAML: ...
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 -mcpu=cascadelake < %s | FileCheck %s
3+
4+
define void @test(ptr %0, i1 %1, i1 %2) {
5+
; CHECK-LABEL: define void @test(
6+
; CHECK-SAME: ptr [[TMP0:%.*]], i1 [[TMP1:%.*]], i1 [[TMP2:%.*]]) #[[ATTR0:[0-9]+]] {
7+
; CHECK-NEXT: br label %[[BB4:.*]]
8+
; CHECK: [[BB4]]:
9+
; CHECK-NEXT: [[TMP5:%.*]] = phi <2 x i32> [ [[TMP12:%.*]], %[[TMP7:.*]] ], [ zeroinitializer, [[TMP3:%.*]] ]
10+
; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <2 x i32> [[TMP5]], <2 x i32> poison, <4 x i32> <i32 0, i32 0, i32 0, i32 1>
11+
; CHECK-NEXT: br i1 [[TMP1]], label %[[TMP7]], label %[[BB14:.*]]
12+
; CHECK: [[TMP7]]:
13+
; CHECK-NEXT: [[TMP8:%.*]] = load ptr, ptr [[TMP0]], align 8
14+
; CHECK-NEXT: [[TMP9:%.*]] = getelementptr i8, ptr [[TMP8]], i64 16
15+
; CHECK-NEXT: [[TMP10:%.*]] = load <2 x i32>, ptr [[TMP9]], align 1
16+
; CHECK-NEXT: [[TMP11:%.*]] = or <2 x i32> [[TMP10]], splat (i32 1)
17+
; CHECK-NEXT: [[TMP12]] = shufflevector <2 x i32> [[TMP11]], <2 x i32> <i32 1, i32 poison>, <2 x i32> <i32 2, i32 1>
18+
; CHECK-NEXT: [[TMP13:%.*]] = call <4 x i32> @llvm.vector.insert.v4i32.v2i32(<4 x i32> <i32 0, i32 0, i32 poison, i32 poison>, <2 x i32> [[TMP11]], i64 2)
19+
; CHECK-NEXT: br i1 [[TMP2]], label %[[BB15:.*]], label %[[BB4]]
20+
; CHECK: [[BB14]]:
21+
; CHECK-NEXT: br label %[[BB15]]
22+
; CHECK: [[BB15]]:
23+
; CHECK-NEXT: [[TMP16:%.*]] = phi <4 x i32> [ [[TMP6]], %[[BB14]] ], [ [[TMP13]], %[[TMP7]] ]
24+
; CHECK-NEXT: [[TMP17:%.*]] = load volatile ptr, ptr null, align 8
25+
; CHECK-NEXT: [[TMP18:%.*]] = getelementptr i8, ptr [[TMP17]], i64 176
26+
; CHECK-NEXT: store <4 x i32> [[TMP16]], ptr [[TMP18]], align 8
27+
; CHECK-NEXT: ret void
28+
;
29+
br label %4
30+
31+
4:
32+
%5 = phi i32 [ %14, %7 ], [ 0, %3 ]
33+
%6 = phi i32 [ 1, %7 ], [ 0, %3 ]
34+
br i1 %1, label %7, label %15
35+
36+
7:
37+
%8 = load ptr, ptr %0, align 8
38+
%9 = getelementptr i8, ptr %8, i64 16
39+
%10 = load i32, ptr %9, align 1
40+
%11 = or i32 %10, 1
41+
%12 = getelementptr i8, ptr %8, i64 20
42+
%13 = load i32, ptr %12, align 1
43+
%14 = or i32 %13, 1
44+
br i1 %2, label %16, label %4
45+
46+
15:
47+
br label %16
48+
49+
16:
50+
%17 = phi i32 [ %6, %15 ], [ 0, %7 ]
51+
%18 = phi i32 [ %6, %15 ], [ %11, %7 ]
52+
%19 = phi i32 [ %5, %15 ], [ %14, %7 ]
53+
%20 = load volatile ptr, ptr null, align 8
54+
%21 = getelementptr i8, ptr %20, i64 176
55+
store i32 %17, ptr %21, align 8
56+
%22 = getelementptr i8, ptr %20, i64 180
57+
store i32 %17, ptr %22, align 4
58+
%23 = getelementptr i8, ptr %20, i64 184
59+
store i32 %18, ptr %23, align 8
60+
%24 = getelementptr i8, ptr %20, i64 188
61+
store i32 %19, ptr %24, align 4
62+
ret void
63+
}

0 commit comments

Comments
 (0)