Skip to content

Commit 2cba218

Browse files
committed
[SLP]Fix PR98133: Inserting PHI after debug-records!
The phi-node-to-be-deleted still should be inserted as the first instruction in the block to avoid random compiler crashes. Fixes #98133
1 parent 042ef40 commit 2cba218

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -4099,7 +4099,11 @@ BoUpSLP::~BoUpSLP() {
40994099
SmallVector<WeakTrackingVH> DeadInsts;
41004100
for (auto *I : DeletedInstructions) {
41014101
if (!I->getParent()) {
4102-
I->insertBefore(F->getEntryBlock().getTerminator());
4102+
if (isa<PHINode>(I))
4103+
I->insertBefore(F->getEntryBlock(),
4104+
F->getEntryBlock().getFirstNonPHIIt());
4105+
else
4106+
I->insertBefore(F->getEntryBlock().getTerminator());
41034107
continue;
41044108
}
41054109
for (Use &U : I->operands()) {
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 -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
3+
4+
define void @foo() {
5+
; CHECK-LABEL: define void @foo() {
6+
; CHECK-NEXT: [[ENTRY:.*]]:
7+
; CHECK-NEXT: #dbg_value(float 0.000000e+00, [[META3:![0-9]+]], !DIExpression(), [[META5:![0-9]+]])
8+
; CHECK-NEXT: br label %[[FOR_BODY:.*]]
9+
; CHECK: [[FOR_BODY]]:
10+
; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x float> [ zeroinitializer, %[[ENTRY]] ], [ zeroinitializer, %[[FOR_BODY]] ]
11+
; CHECK-NEXT: br label %[[FOR_BODY]]
12+
;
13+
entry:
14+
#dbg_value(float 0.000000e+00, !3, !DIExpression(), !5)
15+
br label %for.body
16+
17+
for.body:
18+
%s1.016 = phi float [ 0.000000e+00, %entry ], [ %cond7, %for.body ]
19+
%s0.015 = phi float [ 0.000000e+00, %entry ], [ %cond, %for.body ]
20+
%cond = select i1 false, float 0.000000e+00, float 0.000000e+00
21+
%cond7 = select i1 false, float 0.000000e+00, float 0.000000e+00
22+
br label %for.body
23+
}
24+
25+
!llvm.dbg.cu = !{!0}
26+
!llvm.module.flags = !{!2}
27+
28+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1)
29+
!1 = !DIFile(filename: "repro.c", directory: "/")
30+
!2 = !{i32 2, !"Debug Info Version", i32 3}
31+
!3 = !DILocalVariable(name: "s0", scope: !4)
32+
!4 = distinct !DISubprogram(name: "foo", scope: !1, unit: !0)
33+
!5 = !DILocation(line: 0, scope: !4)
34+
;.
35+
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
36+
; CHECK: [[META1]] = !DIFile(filename: "repro.c", directory: {{.*}})
37+
; CHECK: [[META3]] = !DILocalVariable(name: "s0", scope: [[META4:![0-9]+]])
38+
; CHECK: [[META4]] = distinct !DISubprogram(name: "foo", scope: [[META1]], spFlags: DISPFlagDefinition, unit: [[META0]])
39+
; CHECK: [[META5]] = !DILocation(line: 0, scope: [[META4]])
40+
;.

0 commit comments

Comments
 (0)