Skip to content

Commit 9637b04

Browse files
committed
Improve the effectiveness of ADCE's debug info salvaging
This patch improves the effectiveness of ADCE's debug info salvaging by processing the instructions in reverse order and delaying dropAllReferences until after debug info salvaging. This allows salvaging of entire chains of deleted instructions! Previously we would remove all references from an instruction, which would make it impossible to use that instruction to salvage a later instruction in the instruction stream, because its operands were already removed. Differential Revision: https://reviews.llvm.org/D110462
1 parent 1b998a5 commit 9637b04

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

llvm/lib/Transforms/Scalar/ADCE.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ bool AggressiveDeadCodeElimination::removeDeadInstructions() {
538538
// that have no side effects and do not influence the control flow or return
539539
// value of the function, and may therefore be deleted safely.
540540
// NOTE: We reuse the Worklist vector here for memory efficiency.
541-
for (Instruction &I : instructions(F)) {
541+
for (Instruction &I : llvm::reverse(instructions(F))) {
542542
// Check if the instruction is alive.
543543
if (isLive(&I))
544544
continue;
@@ -554,9 +554,11 @@ bool AggressiveDeadCodeElimination::removeDeadInstructions() {
554554
// Prepare to delete.
555555
Worklist.push_back(&I);
556556
salvageDebugInfo(I);
557-
I.dropAllReferences();
558557
}
559558

559+
for (Instruction *&I : Worklist)
560+
I->dropAllReferences();
561+
560562
for (Instruction *&I : Worklist) {
561563
++NumRemoved;
562564
I->eraseFromParent();

llvm/test/Transforms/Util/salvage-debuginfo.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ define void @f(i32) !dbg !8 {
55
entry:
66
%p_x = inttoptr i32 %0 to i8*
77
%i_x = ptrtoint i8* %p_x to i32
8-
; CHECK: call void @llvm.dbg.value(metadata i8* undef,
9-
; CHECK-SAME: !DIExpression(DW_OP_LLVM_convert, 64, DW_ATE_unsigned,
8+
; CHECK: call void @llvm.dbg.value(metadata i32 %0,
9+
; CHECK-SAME: !DIExpression(DW_OP_LLVM_convert, 32, DW_ATE_unsigned,
10+
; CHECK-SAME: DW_OP_LLVM_convert, 64, DW_ATE_unsigned,
11+
; CHECK-SAME: DW_OP_LLVM_convert, 64, DW_ATE_unsigned,
1012
; CHECK-SAME: DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_stack_value))
1113
call void @llvm.dbg.value(metadata i32 %i_x, metadata !11, metadata !DIExpression()), !dbg !13
1214
ret void, !dbg !13

0 commit comments

Comments
 (0)