[llvm] 6cf11f4 - [GlobalISel][DebugInfo] Salvage trivially dead instructions

Vladislav Dzhidzhoev via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 16 17:55:42 PDT 2022


Author: Vladislav Dzhidzhoev
Date: 2022-09-17T03:54:55+03:00
New Revision: 6cf11f44627967c00adecd48b8ab9b4e97d627fd

URL: https://github.com/llvm/llvm-project/commit/6cf11f44627967c00adecd48b8ab9b4e97d627fd
DIFF: https://github.com/llvm/llvm-project/commit/6cf11f44627967c00adecd48b8ab9b4e97d627fd.diff

LOG: [GlobalISel][DebugInfo] Salvage trivially dead instructions

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.

Reviewed by: arsenm

Differential Revision: https://reviews.llvm.org/D133986

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp b/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
index 28f3b425c67d9..14b8a141af437 100644
--- a/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
@@ -160,6 +160,7 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) {
       // If so, erase it.
       if (isTriviallyDead(MI, MRI)) {
         LLVM_DEBUG(dbgs() << "Is dead; erasing.\n");
+        salvageDebugInfo(MRI, MI);
         MI.eraseFromParent();
         continue;
       }

diff  --git a/llvm/lib/CodeGen/GlobalISel/Legalizer.cpp b/llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
index f09e5b7ce7833..1a13f39c100c9 100644
--- a/llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
@@ -225,6 +225,7 @@ Legalizer::legalizeMachineFunction(MachineFunction &MF, const LegalizerInfo &LI,
       assert(isPreISelGenericOpcode(MI.getOpcode()) &&
              "Expecting generic opcode");
       if (isTriviallyDead(MI, MRI)) {
+        salvageDebugInfo(MRI, MI);
         eraseInstr(MI, MRI, &LocObserver);
         continue;
       }
@@ -272,6 +273,7 @@ Legalizer::legalizeMachineFunction(MachineFunction &MF, const LegalizerInfo &LI,
       assert(isPreISelGenericOpcode(MI.getOpcode()) &&
              "Expecting generic opcode");
       if (isTriviallyDead(MI, MRI)) {
+        salvageDebugInfo(MRI, MI);
         eraseInstr(MI, MRI, &LocObserver);
         continue;
       }

diff  --git a/llvm/test/CodeGen/AArch64/GlobalISel/select-dbg-value.mir b/llvm/test/CodeGen/AArch64/GlobalISel/select-dbg-value.mir
index 316cd580994c8..e015d35916ac3 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/select-dbg-value.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/select-dbg-value.mir
@@ -65,7 +65,8 @@ body: |
     ; 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
 ...


        


More information about the llvm-commits mailing list