[llvm] 9637b04 - Improve the effectiveness of ADCE's debug info salvaging

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 28 10:25:20 PDT 2021


Author: Adrian Prantl
Date: 2021-09-28T10:24:50-07:00
New Revision: 9637b045e6eee71cd34f0f2f80a2ae1ad2a71129

URL: https://github.com/llvm/llvm-project/commit/9637b045e6eee71cd34f0f2f80a2ae1ad2a71129
DIFF: https://github.com/llvm/llvm-project/commit/9637b045e6eee71cd34f0f2f80a2ae1ad2a71129.diff

LOG: 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

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/ADCE.cpp
    llvm/test/Transforms/Util/salvage-debuginfo.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/ADCE.cpp b/llvm/lib/Transforms/Scalar/ADCE.cpp
index 6f3fdb88eda50..b693acceb3f6c 100644
--- a/llvm/lib/Transforms/Scalar/ADCE.cpp
+++ b/llvm/lib/Transforms/Scalar/ADCE.cpp
@@ -538,7 +538,7 @@ bool AggressiveDeadCodeElimination::removeDeadInstructions() {
   // 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 @@ bool AggressiveDeadCodeElimination::removeDeadInstructions() {
     // Prepare to delete.
     Worklist.push_back(&I);
     salvageDebugInfo(I);
-    I.dropAllReferences();
   }
 
+  for (Instruction *&I : Worklist)
+    I->dropAllReferences();
+
   for (Instruction *&I : Worklist) {
     ++NumRemoved;
     I->eraseFromParent();

diff  --git a/llvm/test/Transforms/Util/salvage-debuginfo.ll b/llvm/test/Transforms/Util/salvage-debuginfo.ll
index a1f6f3639f587..ed1baa56017af 100644
--- a/llvm/test/Transforms/Util/salvage-debuginfo.ll
+++ b/llvm/test/Transforms/Util/salvage-debuginfo.ll
@@ -5,8 +5,10 @@ define void @f(i32) !dbg !8 {
 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


        


More information about the llvm-commits mailing list