[PATCH] D133986: [GlobalISel][DebugInfo] Salvage trivially dead instructions

Vladislav Dzhidzhoev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 15 16:14:35 PDT 2022


dzhidzhoev created this revision.
dzhidzhoev added reviewers: aprantl, arsenm, dsanders, jmorse, probinson, dblaikie, LuoYuanke, paquette.
Herald added subscribers: hiraditya, kristof.beyls, rovka.
Herald added a project: All.
dzhidzhoev requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

Use salvageDebugInfo for instructions erased as trivially dead in
GlobalISel.

It would be helpful to implement support of G_PTR_ADD and G_FRAME_INDEX
in salvageDebugInfo in future in order to preserve more variable
location.

Statistics of llvm object files built with vs without this commit on -O2 optimization level (CMAKE_BUILD_TYPE=RelWithDebInfo, -fglobal-isel) on Aarch64 
(macOS):

Number of variables covered by location statistics:

- test-suite GISel - 1074837
- test-suite Patch - 1109099 (+3.18%)
- llvm GISel - 11914074
- llvm Patch - 12356266 (+3.71%)

Number of variables with 100% coverage of parent scope:

- test-suite GISel - 361477
- test-suite Patch - 393043 (+8.73%)
- llvm GISel - 4575700
- llvm GISel+patch - 4858319 (+6.17%)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133986

Files:
  llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
  llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/select-dbg-value.mir


Index: llvm/test/CodeGen/AArch64/GlobalISel/select-dbg-value.mir
===================================================================
--- llvm/test/CodeGen/AArch64/GlobalISel/select-dbg-value.mir
+++ llvm/test/CodeGen/AArch64/GlobalISel/select-dbg-value.mir
@@ -65,7 +65,8 @@
     ; CHECK-LABEL: name: test_dbg_value_dead
     ; CHECK: liveins: $w0
     ; CHECK-NEXT: {{  $}}
-    ; CHECK-NEXT: DBG_VALUE %0:gpr32, $noreg, !7, !DIExpression(), debug-location !9
+    ; CHECK-NEXT: DBG_VALUE %1:gpr64, $noreg, !7, !DIExpression(), debug-location !9
     %0:gpr(s32) = COPY $w0
-    DBG_VALUE %0(s32), $noreg, !7, !DIExpression(), debug-location !9
+    %1:gpr(s64) = G_ZEXT %0:gpr(s32)
+    DBG_VALUE %1(s64), $noreg, !7, !DIExpression(), debug-location !9
 ...
Index: llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
+++ llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
@@ -225,6 +225,7 @@
       assert(isPreISelGenericOpcode(MI.getOpcode()) &&
              "Expecting generic opcode");
       if (isTriviallyDead(MI, MRI)) {
+        salvageDebugInfo(MRI, MI);
         eraseInstr(MI, MRI, &LocObserver);
         continue;
       }
@@ -272,6 +273,7 @@
       assert(isPreISelGenericOpcode(MI.getOpcode()) &&
              "Expecting generic opcode");
       if (isTriviallyDead(MI, MRI)) {
+        salvageDebugInfo(MRI, MI);
         eraseInstr(MI, MRI, &LocObserver);
         continue;
       }
Index: llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
+++ llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
@@ -160,6 +160,7 @@
       // If so, erase it.
       if (isTriviallyDead(MI, MRI)) {
         LLVM_DEBUG(dbgs() << "Is dead; erasing.\n");
+        salvageDebugInfo(MRI, MI);
         MI.eraseFromParent();
         continue;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133986.460533.patch
Type: text/x-patch
Size: 1969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220915/1e3abd92/attachment.bin>


More information about the llvm-commits mailing list