Skip to content

Commit 88c8ddf

Browse files
committed
Improve the effectiveness of BDCE's debug info salvaging
This patch improves the effectiveness of BDCE'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. This reapplies the previous patch with a fix for a use-after-free. Differential Revision: https://reviews.llvm.org/D110568 (cherry picked from commit 9232ca4)
1 parent 8dbf06f commit 88c8ddf

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

llvm/lib/Transforms/Scalar/BDCE.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ static bool bitTrackingDCE(Function &F, DemandedBits &DB) {
106106
(I.getType()->isIntOrIntVectorTy() &&
107107
DB.getDemandedBits(&I).isNullValue() &&
108108
wouldInstructionBeTriviallyDead(&I))) {
109-
salvageDebugInfo(I);
110109
Worklist.push_back(&I);
111-
I.dropAllReferences();
112110
Changed = true;
113111
continue;
114112
}
@@ -155,6 +153,11 @@ static bool bitTrackingDCE(Function &F, DemandedBits &DB) {
155153
}
156154
}
157155

156+
for (Instruction *&I : llvm::reverse(Worklist)) {
157+
salvageDebugInfo(*I);
158+
I->dropAllReferences();
159+
}
160+
158161
for (Instruction *&I : Worklist) {
159162
++NumRemoved;
160163
I->eraseFromParent();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: opt -adce %s -S -o - | FileCheck %s
2+
; RUN: opt -bdce %s -S -o - | FileCheck %s
23
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
34
target triple = "x86_64-apple-macosx"
45
define void @f(i32) !dbg !8 {

0 commit comments

Comments
 (0)