Skip to content

Commit 0e1ffa3

Browse files
committed
[SLP]Fix a crash when comparing phis from unreachable blocks
Need to check if the block is reachable before comparing phis from it to avoid compiler crash when requesting node. Fixes report in #110529 (comment)
1 parent 2cb5241 commit 0e1ffa3

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5724,6 +5724,10 @@ BoUpSLP::getReorderingData(const TreeEntry &TE, bool TopToBottom) {
57245724

57255725
auto CompareByBasicBlocks = [&](BasicBlock *BB1, BasicBlock *BB2) {
57265726
assert(BB1 != BB2 && "Expected different basic blocks.");
5727+
if (!DT->isReachableFromEntry(BB1))
5728+
return false;
5729+
if (!DT->isReachableFromEntry(BB2))
5730+
return true;
57275731
auto *NodeA = DT->getNode(BB1);
57285732
auto *NodeB = DT->getNode(BB2);
57295733
assert(NodeA && "Should only process reachable instructions");
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S --passes=slp-vectorizer -mtriple=aarch64 < %s | FileCheck %s
3+
4+
define void @test() {
5+
; CHECK-LABEL: define void @test() {
6+
; CHECK-NEXT: [[ENTRY:.*]]:
7+
; CHECK-NEXT: [[TMP0:%.*]] = load <2 x i32>, ptr null, align 1
8+
; CHECK-NEXT: br label %[[IF_END:.*]]
9+
; CHECK: [[IF_THEN:.*]]:
10+
; CHECK-NEXT: br label %[[IF_END]]
11+
; CHECK: [[IF_END]]:
12+
; CHECK-NEXT: [[TMP1:%.*]] = phi <2 x i32> [ [[TMP0]], %[[ENTRY]] ], [ poison, %[[IF_THEN]] ]
13+
; CHECK-NEXT: [[TMP2:%.*]] = extractelement <2 x i32> [[TMP1]], i32 0
14+
; CHECK-NEXT: store i32 [[TMP2]], ptr null, align 1
15+
; CHECK-NEXT: br label %[[TRAP:.*]]
16+
; CHECK: [[BB3:.*:]]
17+
; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x i32> [[TMP1]], i32 1
18+
; CHECK-NEXT: store i32 [[TMP4]], ptr null, align 1
19+
; CHECK-NEXT: ret void
20+
; CHECK: [[TRAP]]:
21+
; CHECK-NEXT: unreachable
22+
;
23+
entry:
24+
%g_2197.real32.pre = load i32, ptr null, align 1
25+
%g_2197.imag33.pre = load i32, ptr getelementptr inbounds nuw ({ i32, i32 }, ptr null, i32 0, i32 1), align 1
26+
br label %if.end
27+
28+
if.then:
29+
br label %if.end
30+
31+
if.end:
32+
%g_2197.imag33 = phi i32 [ %g_2197.imag33.pre, %entry ], [ 0, %if.then ]
33+
%g_2197.real32 = phi i32 [ %g_2197.real32.pre, %entry ], [ 0, %if.then ]
34+
store i32 %g_2197.real32, ptr null, align 1
35+
br label %trap
36+
37+
0:
38+
store i32 %g_2197.imag33, ptr null, align 1
39+
ret void
40+
41+
trap:
42+
unreachable
43+
}

0 commit comments

Comments
 (0)