[llvm] 2cba218 - [SLP]Fix PR98133: Inserting PHI after debug-records!
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 9 05:51:23 PDT 2024
Author: Alexey Bataev
Date: 2024-07-09T05:44:45-07:00
New Revision: 2cba218ca573f5da6ff301df59aa686d2e3e40c5
URL: https://github.com/llvm/llvm-project/commit/2cba218ca573f5da6ff301df59aa686d2e3e40c5
DIFF: https://github.com/llvm/llvm-project/commit/2cba218ca573f5da6ff301df59aa686d2e3e40c5.diff
LOG: [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 https://github.com/llvm/llvm-project/issues/98133
Added:
llvm/test/Transforms/SLPVectorizer/X86/phi-node-deletion.ll
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 5bcab7e929231..61830458e973e 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -4099,7 +4099,11 @@ BoUpSLP::~BoUpSLP() {
SmallVector<WeakTrackingVH> DeadInsts;
for (auto *I : DeletedInstructions) {
if (!I->getParent()) {
- I->insertBefore(F->getEntryBlock().getTerminator());
+ if (isa<PHINode>(I))
+ I->insertBefore(F->getEntryBlock(),
+ F->getEntryBlock().getFirstNonPHIIt());
+ else
+ I->insertBefore(F->getEntryBlock().getTerminator());
continue;
}
for (Use &U : I->operands()) {
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/phi-node-deletion.ll b/llvm/test/Transforms/SLPVectorizer/X86/phi-node-deletion.ll
new file mode 100644
index 0000000000000..db1d498393043
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/phi-node-deletion.ll
@@ -0,0 +1,40 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+
+define void @foo() {
+; CHECK-LABEL: define void @foo() {
+; CHECK-NEXT: [[ENTRY:.*]]:
+; CHECK-NEXT: #dbg_value(float 0.000000e+00, [[META3:![0-9]+]], !DIExpression(), [[META5:![0-9]+]])
+; CHECK-NEXT: br label %[[FOR_BODY:.*]]
+; CHECK: [[FOR_BODY]]:
+; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x float> [ zeroinitializer, %[[ENTRY]] ], [ zeroinitializer, %[[FOR_BODY]] ]
+; CHECK-NEXT: br label %[[FOR_BODY]]
+;
+entry:
+ #dbg_value(float 0.000000e+00, !3, !DIExpression(), !5)
+ br label %for.body
+
+for.body:
+ %s1.016 = phi float [ 0.000000e+00, %entry ], [ %cond7, %for.body ]
+ %s0.015 = phi float [ 0.000000e+00, %entry ], [ %cond, %for.body ]
+ %cond = select i1 false, float 0.000000e+00, float 0.000000e+00
+ %cond7 = select i1 false, float 0.000000e+00, float 0.000000e+00
+ br label %for.body
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1)
+!1 = !DIFile(filename: "repro.c", directory: "/")
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = !DILocalVariable(name: "s0", scope: !4)
+!4 = distinct !DISubprogram(name: "foo", scope: !1, unit: !0)
+!5 = !DILocation(line: 0, scope: !4)
+;.
+; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
+; CHECK: [[META1]] = !DIFile(filename: "repro.c", directory: {{.*}})
+; CHECK: [[META3]] = !DILocalVariable(name: "s0", scope: [[META4:![0-9]+]])
+; CHECK: [[META4]] = distinct !DISubprogram(name: "foo", scope: [[META1]], spFlags: DISPFlagDefinition, unit: [[META0]])
+; CHECK: [[META5]] = !DILocation(line: 0, scope: [[META4]])
+;.
More information about the llvm-commits
mailing list