[llvm] 12a2f74 - [DebugInfo][InstrRef] Prefer stack locations for variables
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 17 07:26:29 PDT 2022
Author: Jeremy Morse
Date: 2022-03-17T14:26:15Z
New Revision: 12a2f7494e745eb4c90133ea17cadac3a8eb8d07
URL: https://github.com/llvm/llvm-project/commit/12a2f7494e745eb4c90133ea17cadac3a8eb8d07
DIFF: https://github.com/llvm/llvm-project/commit/12a2f7494e745eb4c90133ea17cadac3a8eb8d07.diff
LOG: [DebugInfo][InstrRef] Prefer stack locations for variables
This patch adjusts what location is picked for a known variable value --
preferring to leave locations on the stack, even when a value is re-loaded
into a register. The benefit is reduced location list entropy, on a
clang-3.4 build I found that .debug_loclists reduces in size by 6%, from
29Mb down to 27Mb.
Testing: a few tests need the stack slot to be written to explicitly, to
force LiveDebugValues into restoring the variable location to a register.
I've added an explicit test for the desired behaviour in
livedebugvalues_recover_clobbers.mir .
Differential Revision: https://reviews.llvm.org/D120732
Added:
Modified:
llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
llvm/test/DebugInfo/COFF/pieces.ll
llvm/test/DebugInfo/MIR/InstrRef/livedebugvalues_recover_clobbers.mir
llvm/test/DebugInfo/MIR/X86/live-debug-values-restore.mir
llvm/test/DebugInfo/X86/pr34545.ll
llvm/test/DebugInfo/X86/spill-nospill.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
index 1c0e5acac8bbd..74f6e6e8fbe7b 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -1634,11 +1634,6 @@ bool InstrRefBasedLDV::transferSpillOrRestoreInst(MachineInstr &MI) {
LocIdx SrcIdx = MTracker->getSpillMLoc(SpillID);
auto ReadValue = MTracker->readMLoc(SrcIdx);
MTracker->setReg(DestReg, ReadValue);
-
- if (TTracker) {
- LocIdx DstLoc = MTracker->getRegMLoc(DestReg);
- TTracker->transferMlocs(SrcIdx, DstLoc, MI.getIterator());
- }
};
for (MCSubRegIterator SRI(Reg, TRI, false); SRI.isValid(); ++SRI) {
diff --git a/llvm/test/DebugInfo/COFF/pieces.ll b/llvm/test/DebugInfo/COFF/pieces.ll
index 01dffde30e52b..76c330a996b2f 100644
--- a/llvm/test/DebugInfo/COFF/pieces.ll
+++ b/llvm/test/DebugInfo/COFF/pieces.ll
@@ -105,8 +105,6 @@
; ASM: #APP
; ASM: #NO_APP
; ASM: movl [[offset_o_x]](%rsp), %eax # 4-byte Reload
-; ASM: [[spill_o_x_end:\.Ltmp[0-9]+]]:
-; ASM: #DEBUG_VALUE: bitpiece_spill:o <- [DW_OP_LLVM_fragment 32 32] $eax
; ASM: retq
; ASM: [[spill_o_x_end_func:\.Ltmp[0-9]+]]:
; ASM-NEXT: .Lfunc_end4:
@@ -235,8 +233,7 @@
; ASM: .asciz "bitpiece_spill" # Function name
; ASM: .short 4414 # Record kind: S_LOCAL
; ASM: .asciz "o"
-; ASM: .cv_def_range [[spill_o_x_start]] [[spill_o_x_end]], reg_rel, 335, 65, 36
-; ASM: .cv_def_range [[spill_o_x_end]] .Lfunc_end4, subfield_reg, 17, 4
+; ASM: .cv_def_range [[spill_o_x_start]] .Lfunc_end4, reg_rel, 335, 65, 36
; OBJ-LABEL: GlobalProcIdSym {
; OBJ: Kind: S_GPROC32_ID (0x1147)
diff --git a/llvm/test/DebugInfo/MIR/InstrRef/livedebugvalues_recover_clobbers.mir b/llvm/test/DebugInfo/MIR/InstrRef/livedebugvalues_recover_clobbers.mir
index c41610fdc2017..83c92c09df1a5 100644
--- a/llvm/test/DebugInfo/MIR/InstrRef/livedebugvalues_recover_clobbers.mir
+++ b/llvm/test/DebugInfo/MIR/InstrRef/livedebugvalues_recover_clobbers.mir
@@ -76,6 +76,17 @@ body: |
; CHECK-NEXT: $ebx = MOV32ri
; CHECK-NEXT: DBG_VALUE $rsp
+ ;; Try re-loading the variable value from the stack; we shouldn't issue a
+ ;; DBG_VALUE to follow it, the stack locations are usually longer lived and
+ ;; this reduces location list entropy. Then, clobber the stack location,
+ ;; and check that we can relocate the variable to being in the loaded
+ ;; register.
+ $ebx = MOV32rm $rsp, 1, _, -12, _ :: (load 4 from %stack.0)
+ MOV32mr $rsp, 1, _, -12, _, killed $esi :: (store 4 into %stack.0)
+ ; CHECK: $ebx = MOV32rm
+ ; CHECK-NEXT: MOV32mr $rsp
+ ; CHECK-NEXT: DBG_VALUE $ebx
+
;; Now test copies and register masks.
$eax = COPY $ebx
DBG_VALUE $ebx, $noreg, !16, !DIExpression(), debug-location !17
diff --git a/llvm/test/DebugInfo/MIR/X86/live-debug-values-restore.mir b/llvm/test/DebugInfo/MIR/X86/live-debug-values-restore.mir
index c4d30eaca2e69..65c57761621bd 100644
--- a/llvm/test/DebugInfo/MIR/X86/live-debug-values-restore.mir
+++ b/llvm/test/DebugInfo/MIR/X86/live-debug-values-restore.mir
@@ -34,6 +34,8 @@
# Check for the restore.
# CHECK: $rdi = MOV64rm $rsp,{{.*-8.*}}:: (load (s64) from %stack.0)
+# CHECK-NEXT: $rax = MOV64ri 0
+# CHECK-NEXT: MOV64mr
# CHECK-NEXT: DBG_VALUE $rdi,{{.*}}![[PVAR]], !DIExpression()
--- |
@@ -310,6 +312,9 @@ body: |
MOV64mr $rsp, 1, $noreg, -8, $noreg, killed renamable $rdi :: (store (s64) into %stack.0)
INLINEASM &"", 1, 12, implicit-def dead early-clobber $rax, 12, implicit-def dead early-clobber $rbx, 12, implicit-def dead early-clobber $rcx, 12, implicit-def dead early-clobber $rdx, 12, implicit-def dead early-clobber $rsi, 12, implicit-def dead early-clobber $rdi, 12, implicit-def dead early-clobber $rbp, 12, implicit-def dead early-clobber $r8, 12, implicit-def dead early-clobber $r9, 12, implicit-def dead early-clobber $r10, 12, implicit-def dead early-clobber $r11, 12, implicit-def dead early-clobber $r12, 12, implicit-def dead early-clobber $r13, 12, implicit-def dead early-clobber $r14, 12, implicit-def dead early-clobber $r15, 12, implicit-def dead early-clobber $eflags, !20, debug-location !18
renamable $rdi = MOV64rm $rsp, 1, $noreg, -8, $noreg :: (load (s64) from %stack.0)
+ ; Clobber stack location to force variable location to move to $rdi.
+ $rax = MOV64ri 0
+ MOV64mr $rsp, 1, _, -8, _, killed renamable $rax :: (store (s64) into %stack.0)
$rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp
CFI_INSTRUCTION def_cfa_offset 48
$r12 = frame-destroy POP64r implicit-def $rsp, implicit $rsp
@@ -491,6 +496,9 @@ body: |
MOV64mr $rsp, 1, $noreg, -8, $noreg, killed renamable $rdi :: (store (s64) into %stack.0)
INLINEASM &"", 1, 12, implicit-def dead early-clobber $rax, 12, implicit-def dead early-clobber $rbx, 12, implicit-def dead early-clobber $rcx, 12, implicit-def dead early-clobber $rdx, 12, implicit-def dead early-clobber $rsi, 12, implicit-def dead early-clobber $rdi, 12, implicit-def dead early-clobber $rbp, 12, implicit-def dead early-clobber $r8, 12, implicit-def dead early-clobber $r9, 12, implicit-def dead early-clobber $r10, 12, implicit-def dead early-clobber $r11, 12, implicit-def dead early-clobber $r12, 12, implicit-def dead early-clobber $r13, 12, implicit-def dead early-clobber $r14, 12, implicit-def dead early-clobber $r15, 12, implicit-def dead early-clobber $eflags, !220, debug-location !218
renamable $rdi = MOV64rm $rsp, 1, $noreg, -8, $noreg :: (load (s64) from %stack.0)
+ ; Clobber stack location to force variable location to move to $rdi.
+ $rax = MOV64ri 0
+ MOV64mr $rsp, 1, _, -8, _, killed renamable $rax :: (store (s64) into %stack.0)
$rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp
CFI_INSTRUCTION def_cfa_offset 48
$r12 = frame-destroy POP64r implicit-def $rsp, implicit $rsp
@@ -628,6 +636,9 @@ body: |
liveins: $rbx, $r12, $r13, $r14, $r15, $rbp
renamable $rdi = MOV64rm $rsp, 1, $noreg, -8, $noreg :: (load (s64) from %stack.0)
+ ; Clobber stack location to force variable location to move to $rdi.
+ $rax = MOV64ri 0
+ MOV64mr $rsp, 1, _, -8, _, killed renamable $rax :: (store (s64) into %stack.0)
renamable $eax = MOV32rm killed renamable $rdi, 1, $noreg, 4, $noreg, debug-location !323 :: (load (s32) from %ir.add.ptr, !tbaa !24)
RET64 $eax, debug-location !328
@@ -715,6 +726,9 @@ body: |
MOV64mr $rsp, 1, $noreg, -8, $noreg, killed renamable $rdi :: (store (s64) into %stack.0)
INLINEASM &"", 1, 12, implicit-def dead early-clobber $rax, 12, implicit-def dead early-clobber $rbx, 12, implicit-def dead early-clobber $rcx, 12, implicit-def dead early-clobber $rdx, 12, implicit-def dead early-clobber $rsi, 12, implicit-def dead early-clobber $rdi, 12, implicit-def dead early-clobber $rbp, 12, implicit-def dead early-clobber $r8, 12, implicit-def dead early-clobber $r9, 12, implicit-def dead early-clobber $r10, 12, implicit-def dead early-clobber $r11, 12, implicit-def dead early-clobber $r12, 12, implicit-def dead early-clobber $r13, 12, implicit-def dead early-clobber $r14, 12, implicit-def dead early-clobber $r15, 12, implicit-def dead early-clobber $eflags, !20, debug-location !409
renamable $rdi = MOV64rm $rsp, 1, $noreg, -8, $noreg :: (load (s64) from %stack.0)
+ ; Clobber stack location to force variable location to move to $rdi.
+ $rax = MOV64ri 0
+ MOV64mr $rsp, 1, _, -8, _, killed renamable $rax :: (store (s64) into %stack.0)
$rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp
CFI_INSTRUCTION def_cfa_offset 48
$r12 = frame-destroy POP64r implicit-def $rsp, implicit $rsp
diff --git a/llvm/test/DebugInfo/X86/pr34545.ll b/llvm/test/DebugInfo/X86/pr34545.ll
index 2f50362d7ad8a..68603fc54acb0 100644
--- a/llvm/test/DebugInfo/X86/pr34545.ll
+++ b/llvm/test/DebugInfo/X86/pr34545.ll
@@ -1,7 +1,7 @@
; RUN: llc -O1 -filetype=asm -mtriple x86_64-unknown-linux-gnu -mcpu=x86-64 \
; RUN: -o - %s -stop-after=livedebugvars \
; RUN: -experimental-debug-variable-locations=false \
-; RUN: | FileCheck %s --check-prefixes=CHECK
+; RUN: | FileCheck %s --check-prefixes=CHECK,VARLOCS
; RUN: llc -O1 -filetype=asm -mtriple x86_64-unknown-linux-gnu -mcpu=x86-64 \
; RUN: -o - %s -stop-after=livedebugvars \
; RUN: -experimental-debug-variable-locations=true \
@@ -16,7 +16,7 @@
; INSTRREF: DBG_INSTR_REF 2, 0
; CHECK: DBG_VALUE $eax
; CHECK: DBG_VALUE $rsp, 0, !{{[0-9]+}}, !DIExpression(DW_OP_constu, 4, DW_OP_minus)
-; CHECK: DBG_VALUE $eax
+; VARLOCS: DBG_VALUE $eax
; CHECK: $eax = SHL32rCL killed renamable $eax,
; INSTRREF-SAME: debug-instr-number 3
; INSTRREF: DBG_INSTR_REF 3, 0
diff --git a/llvm/test/DebugInfo/X86/spill-nospill.ll b/llvm/test/DebugInfo/X86/spill-nospill.ll
index c8a680067fb53..7dec14e892f51 100644
--- a/llvm/test/DebugInfo/X86/spill-nospill.ll
+++ b/llvm/test/DebugInfo/X86/spill-nospill.ll
@@ -37,13 +37,11 @@
; CHECK: movl %[[CSR]], %ecx
; CHECK: callq g
; CHECK: movl [[X_OFFS]](%rsp), %eax # 4-byte Reload
-; CHECK: #DEBUG_VALUE: f:x <- $eax
+;; Variable value remains on stack, location left pointing there.
; CHECK: addl %[[CSR]], %eax
; DWARF: DW_TAG_variable
; DWARF-NEXT: DW_AT_location (
-; DWARF-NEXT: [{{.*}}, {{.*}}): DW_OP_breg7 RSP+36
-; DWARF-NEXT: [{{.*}}, {{.*}}): DW_OP_reg0 RAX
; DWARF-NEXT: [{{.*}}, {{.*}}): DW_OP_breg7 RSP+36)
; DWARF-NEXT: DW_AT_name ("x")
More information about the llvm-commits
mailing list