Skip to content

Commit 2601d6f

Browse files
committed
[SLP]Fix PR102187: do not insert extractelement before landingpad instruction.
Landingpad instruction must be the very first instruction after the phi nodes, so need to inser extractelement/shuffles after this instruction. Fixes #102187
1 parent 4b6e3e3 commit 2601d6f

File tree

2 files changed

+62
-8
lines changed

2 files changed

+62
-8
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14049,12 +14049,19 @@ Value *BoUpSLP::vectorizeTree(
1404914049
"ExternallyUsedValues map or remain as scalar in vectorized "
1405014050
"instructions");
1405114051
if (auto *VecI = dyn_cast<Instruction>(Vec)) {
14052-
if (auto *PHI = dyn_cast<PHINode>(VecI))
14053-
Builder.SetInsertPoint(PHI->getParent(),
14054-
PHI->getParent()->getFirstNonPHIIt());
14055-
else
14052+
if (auto *PHI = dyn_cast<PHINode>(VecI)) {
14053+
if (PHI->getParent()->isLandingPad())
14054+
Builder.SetInsertPoint(
14055+
PHI->getParent(),
14056+
std::next(
14057+
PHI->getParent()->getLandingPadInst()->getIterator()));
14058+
else
14059+
Builder.SetInsertPoint(PHI->getParent(),
14060+
PHI->getParent()->getFirstNonPHIIt());
14061+
} else {
1405614062
Builder.SetInsertPoint(VecI->getParent(),
1405714063
std::next(VecI->getIterator()));
14064+
}
1405814065
} else {
1405914066
Builder.SetInsertPoint(&F->getEntryBlock(), F->getEntryBlock().begin());
1406014067
}
@@ -14080,11 +14087,18 @@ Value *BoUpSLP::vectorizeTree(
1408014087
auto VecIt = VectorCasts.find(Key);
1408114088
if (VecIt == VectorCasts.end()) {
1408214089
IRBuilderBase::InsertPointGuard Guard(Builder);
14083-
if (auto *IVec = dyn_cast<PHINode>(Vec))
14084-
Builder.SetInsertPoint(
14085-
IVec->getParent()->getFirstNonPHIOrDbgOrLifetime());
14086-
else if (auto *IVec = dyn_cast<Instruction>(Vec))
14090+
if (auto *IVec = dyn_cast<PHINode>(Vec)) {
14091+
if (IVec->getParent()->isLandingPad())
14092+
Builder.SetInsertPoint(IVec->getParent(),
14093+
std::next(IVec->getParent()
14094+
->getLandingPadInst()
14095+
->getIterator()));
14096+
else
14097+
Builder.SetInsertPoint(
14098+
IVec->getParent()->getFirstNonPHIOrDbgOrLifetime());
14099+
} else if (auto *IVec = dyn_cast<Instruction>(Vec)) {
1408714100
Builder.SetInsertPoint(IVec->getNextNonDebugInstruction());
14101+
}
1408814102
Vec = Builder.CreateIntCast(
1408914103
Vec,
1409014104
getWidenedType(
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
3+
4+
define void @test() personality ptr null {
5+
; CHECK-LABEL: define void @test() personality ptr null {
6+
; CHECK-NEXT: [[BB:.*]]:
7+
; CHECK-NEXT: invoke void null()
8+
; CHECK-NEXT: to label %[[BB65:.*]] unwind label %[[BB4:.*]]
9+
; CHECK: [[BB2:.*]]:
10+
; CHECK-NEXT: invoke void null()
11+
; CHECK-NEXT: to label %[[BB65]] unwind label %[[BB4]]
12+
; CHECK: [[BB4]]:
13+
; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x i32> [ zeroinitializer, %[[BB]] ], [ poison, %[[BB2]] ]
14+
; CHECK-NEXT: [[LANDINGPAD:%.*]] = landingpad { ptr, i32 }
15+
; CHECK-NEXT: cleanup
16+
; CHECK-NEXT: [[TMP1:%.*]] = extractelement <2 x i32> [[TMP0]], i32 1
17+
; CHECK-NEXT: call void null(i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]], i32 [[TMP1]])
18+
; CHECK-NEXT: ret void
19+
; CHECK: [[BB65]]:
20+
; CHECK-NEXT: ret void
21+
;
22+
bb:
23+
invoke void null()
24+
to label %bb65 unwind label %bb4
25+
26+
bb2:
27+
invoke void null()
28+
to label %bb65 unwind label %bb4
29+
30+
bb4:
31+
%phi5 = phi i32 [ 0, %bb ], [ 0, %bb2 ]
32+
%phi6 = phi i32 [ 0, %bb ], [ 0, %bb2 ]
33+
%landingpad = landingpad { ptr, i32 }
34+
cleanup
35+
call void null(i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5)
36+
ret void
37+
38+
bb65:
39+
ret void
40+
}

0 commit comments

Comments
 (0)