[PATCH] D110568: Improve the effectiveness of BDCE's debug info salvaging
Adrian Prantl via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 27 10:15:32 PDT 2021
aprantl created this revision.
aprantl added reviewers: djtodoro, 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 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.
See also https://reviews.llvm.org/D110462
https://reviews.llvm.org/D110568
Files:
llvm/lib/Transforms/Scalar/BDCE.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
@@ -1,4 +1,5 @@
; RUN: opt -adce %s -S -o - | FileCheck %s
+; RUN: opt -bdce %s -S -o - | FileCheck %s
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx"
define void @f(i32) !dbg !8 {
Index: llvm/lib/Transforms/Scalar/BDCE.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/BDCE.cpp
+++ llvm/lib/Transforms/Scalar/BDCE.cpp
@@ -93,7 +93,7 @@
static bool bitTrackingDCE(Function &F, DemandedBits &DB) {
SmallVector<Instruction*, 128> Worklist;
bool Changed = false;
- for (Instruction &I : instructions(F)) {
+ for (Instruction &I : llvm::reverse(instructions(F))) {
// If the instruction has side effects and no non-dbg uses,
// skip it. This way we avoid computing known bits on an instruction
// that will not help us.
@@ -108,7 +108,6 @@
wouldInstructionBeTriviallyDead(&I))) {
salvageDebugInfo(I);
Worklist.push_back(&I);
- I.dropAllReferences();
Changed = true;
continue;
}
@@ -155,6 +154,9 @@
}
}
+ for (Instruction *&I : Worklist)
+ I->dropAllReferences();
+
for (Instruction *&I : Worklist) {
++NumRemoved;
I->eraseFromParent();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110568.375324.patch
Type: text/x-patch
Size: 1495 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210927/296277be/attachment.bin>
More information about the llvm-commits
mailing list