[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
This commit is contained in:
Vladislav Dzhidzhoev 2022-09-10 02:15:39 +03:00
parent f1a11d770e
commit 6cf11f4462
3 changed files with 6 additions and 2 deletions
llvm
lib/CodeGen/GlobalISel
test/CodeGen/AArch64/GlobalISel

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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
...