Skip to content

Commit eb39605

Browse files
committed
[SLP]Do not schedule terminate copyable from main op basic block
If the copyable instruction is a terminate instruction from the same block, as the potential main instruction, such instruction cannot be copyable and the value list cannot be modeled as instructions with same (and copyables) opcodes. Fixes #155183
1 parent 0a16d1a commit eb39605

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10638,8 +10638,19 @@ class InstructionsCompatibilityAnalysis {
1063810638
}
1063910639
}
1064010640
}
10641-
if (MainOp)
10641+
if (MainOp) {
10642+
// Do not match, if any copyable is a terminator from the same block as
10643+
// the main operation.
10644+
if (any_of(VL, [&](Value *V) {
10645+
auto *I = dyn_cast<Instruction>(V);
10646+
return I && I->getParent() == MainOp->getParent() &&
10647+
I->isTerminator();
10648+
})) {
10649+
MainOp = nullptr;
10650+
return;
10651+
}
1064210652
MainOpcode = MainOp->getOpcode();
10653+
}
1064310654
}
1064410655

1064510656
/// Returns the idempotent value for the \p MainOp with the detected \p
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=x86_64-unknown-linux-gnu < %s | FileCheck %s
3+
4+
define void @test() gc "statepoint-example" personality ptr null {
5+
; CHECK-LABEL: define void @test() gc "statepoint-example" personality ptr null {
6+
; CHECK-NEXT: [[BB:.*:]]
7+
; CHECK-NEXT: [[INVOKE:%.*]] = invoke i32 null(ptr addrspace(1) null, i32 0, i32 0, i32 0)
8+
; CHECK-NEXT: to label %[[BB2:.*]] unwind label %[[BB8:.*]]
9+
; CHECK: [[BB2]]:
10+
; CHECK-NEXT: [[ADD3:%.*]] = add i32 [[INVOKE]], 0
11+
; CHECK-NEXT: br label %[[BB4:.*]]
12+
; CHECK: [[BB4]]:
13+
; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[ADD3]], %[[BB2]] ]
14+
; CHECK-NEXT: [[PHI5:%.*]] = phi i32 [ 0, %[[BB2]] ]
15+
; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x i32> [ zeroinitializer, %[[BB2]] ]
16+
; CHECK-NEXT: ret void
17+
; CHECK: [[BB8]]:
18+
; CHECK-NEXT: [[LANDINGPAD:%.*]] = landingpad { ptr, i32 }
19+
; CHECK-NEXT: cleanup
20+
; CHECK-NEXT: ret void
21+
;
22+
bb:
23+
%add = add i32 0, 0
24+
%add1 = add i32 0, 0
25+
%invoke = invoke i32 null(ptr addrspace(1) null, i32 0, i32 0, i32 0)
26+
to label %bb2 unwind label %bb8
27+
28+
bb2:
29+
%add3 = add i32 %invoke, 0
30+
br label %bb4
31+
32+
bb4:
33+
%phi = phi i32 [ %add3, %bb2 ]
34+
%phi5 = phi i32 [ 0, %bb2 ]
35+
%phi6 = phi i32 [ %add, %bb2 ]
36+
%phi7 = phi i32 [ %add1, %bb2 ]
37+
ret void
38+
39+
bb8:
40+
%landingpad = landingpad { ptr, i32 }
41+
cleanup
42+
ret void
43+
}

0 commit comments

Comments
 (0)