[PATCH] D110462: Improve the effectiveness of ADCE's debug info salvaging
Adrian Prantl via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 24 17:12:48 PDT 2021
aprantl created this revision.
aprantl added reviewers: djtodoro, jmorse, StephenTozer, rastogishubham.
aprantl added a project: debug-info.
Herald added a subscriber: hiraditya.
aprantl requested review of this revision.
Herald added a project: LLVM.
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.
https://reviews.llvm.org/D110462
Files:
llvm/lib/Transforms/Scalar/ADCE.cpp
llvm/test/Transforms/Util/salvage-debuginfo.ll
Index: llvm/test/Transforms/Util/salvage-debuginfo.ll
===================================================================
--- llvm/test/Transforms/Util/salvage-debuginfo.ll
+++ llvm/test/Transforms/Util/salvage-debuginfo.ll
@@ -5,8 +5,10 @@
entry:
%p_x = inttoptr i32 %0 to i8*
%i_x = ptrtoint i8* %p_x to i32
- ; CHECK: call void @llvm.dbg.value(metadata i8* undef,
- ; CHECK-SAME: !DIExpression(DW_OP_LLVM_convert, 64, DW_ATE_unsigned,
+ ; CHECK: call void @llvm.dbg.value(metadata i32 %0,
+ ; CHECK-SAME: !DIExpression(DW_OP_LLVM_convert, 32, DW_ATE_unsigned,
+ ; CHECK-SAME: DW_OP_LLVM_convert, 64, DW_ATE_unsigned,
+ ; CHECK-SAME: DW_OP_LLVM_convert, 64, DW_ATE_unsigned,
; CHECK-SAME: DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_stack_value))
call void @llvm.dbg.value(metadata i32 %i_x, metadata !11, metadata !DIExpression()), !dbg !13
ret void, !dbg !13
Index: llvm/lib/Transforms/Scalar/ADCE.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/ADCE.cpp
+++ llvm/lib/Transforms/Scalar/ADCE.cpp
@@ -538,7 +538,7 @@
// that have no side effects and do not influence the control flow or return
// value of the function, and may therefore be deleted safely.
// NOTE: We reuse the Worklist vector here for memory efficiency.
- for (Instruction &I : instructions(F)) {
+ for (Instruction &I : llvm::reverse(instructions(F))) {
// Check if the instruction is alive.
if (isLive(&I))
continue;
@@ -554,9 +554,11 @@
// Prepare to delete.
Worklist.push_back(&I);
salvageDebugInfo(I);
- I.dropAllReferences();
}
+ for (Instruction *&I : Worklist)
+ I->dropAllReferences();
+
for (Instruction *&I : Worklist) {
++NumRemoved;
I->eraseFromParent();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110462.374999.patch
Type: text/x-patch
Size: 1831 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210925/d233c0bd/attachment.bin>
More information about the llvm-commits
mailing list