[llvm] [Passes] opt Segmentation fault with the pass "codegenprepare" (PR #89566)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 21 20:31:05 PDT 2024


https://github.com/coderchenlin created https://github.com/llvm/llvm-project/pull/89566

None

>From 6ade1a901b892dcb868664a04b0f93a98024d73f Mon Sep 17 00:00:00 2001
From: coderchenlin <chenlin048830 at gmail.com>
Date: Wed, 17 Apr 2024 21:01:52 +0800
Subject: [PATCH 1/2] [BasicBlockUtils] Remove redundant llvm.dbg instructions
 after blocks merged

There will generate more redundant llvm.dbg instructions when compiling
with "-g" flag, and increase compile time. The issue is happened after
loop-unroll pass.`

Fixes #89073.
---
 llvm/lib/Transforms/Utils/BasicBlockUtils.cpp              | 4 ++++
 llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll | 1 -
 llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue.ll         | 1 -
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 5aa59acfa6df99..cbf66ce2796db8 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -333,6 +333,10 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU,
   // Finally, erase the old block and update dominator info.
   DeleteDeadBlock(BB, DTU);
 
+  // Remove redundant "llvm.dbg" instrunctions after blocks merged.
+  if (PredBB->getParent()->getSubprogram())
+    RemoveRedundantDbgInstrs(PredBB);
+
   return true;
 }
 
diff --git a/llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll b/llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll
index e00d1daf71de58..5af73e789f11ce 100644
--- a/llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll
+++ b/llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll
@@ -9,7 +9,6 @@ init:
 
 ; CHECK:  %vala = load i64, ptr %ptr
 ; CHECK-NEXT:  call void @llvm.dbg.value(metadata i64 %vala, metadata [[MD:![0-9]*]]
-; CHECK-NEXT:  call void @llvm.dbg.value(metadata i64 %vala, metadata [[MD]]
 ; CHECK-NEXT:  %valbmasked = and i64 %vala, 1
 
 a:                                              ; preds = %init
diff --git a/llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue.ll b/llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue.ll
index af7da45ec089cc..c5d723c4e3dd61 100644
--- a/llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue.ll
+++ b/llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue.ll
@@ -47,7 +47,6 @@ define i1 @hoist_with_debug2(i32 %x) !dbg !22 {
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[TOBOOL_NOT:%.*]] = icmp ugt i32 [[X:%.*]], 2
 ; CHECK-NEXT:    call void @llvm.dbg.value(metadata i32 [[X]], metadata [[META21:![0-9]+]], metadata !DIExpression()), !dbg [[DBG23:![0-9]+]]
-; CHECK-NEXT:    call void @llvm.dbg.value(metadata i32 [[X]], metadata [[META21]], metadata !DIExpression()), !dbg [[DBG23]]
 ; CHECK-NEXT:    [[DOT:%.*]] = select i1 [[TOBOOL_NOT]], i1 false, i1 true
 ; CHECK-NEXT:    ret i1 [[DOT]]
 ;

>From b358c6d017860b67008cf3ac14eea779a7007561 Mon Sep 17 00:00:00 2001
From: coderchenlin <chenlin138 at huawei.com>
Date: Mon, 22 Apr 2024 11:11:12 +0800
Subject: [PATCH 2/2] [Passes] The passes executed with "opt" tools should be
 independent from target. However, the CodegenPrepare pass is depended on
 target, it needs target to implement "getSubtargetImpl". the follow command
 will make the programe crash.

 "opt -passes=codegenprepare mutant.bc -o mutant.opt.bc"

Thus, I think removing CodegenPrepare form PassRegistry is the best
way to stop it.

 fixes #88692
---
 llvm/lib/Passes/PassRegistry.def | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 41f16d0915bf23..abb1227f5cab2d 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -309,7 +309,6 @@ FUNCTION_PASS("break-crit-edges", BreakCriticalEdgesPass())
 FUNCTION_PASS("callbr-prepare", CallBrPreparePass())
 FUNCTION_PASS("callsite-splitting", CallSiteSplittingPass())
 FUNCTION_PASS("chr", ControlHeightReductionPass())
-FUNCTION_PASS("codegenprepare", CodeGenPreparePass(TM))
 FUNCTION_PASS("consthoist", ConstantHoistingPass())
 FUNCTION_PASS("constraint-elimination", ConstraintEliminationPass())
 FUNCTION_PASS("coro-elide", CoroElidePass())



More information about the llvm-commits mailing list