[PATCH] D120732: [DebugInfo][InstrRef] Prefer stack locations for variables over restored registers
Jeremy Morse via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 1 07:45:05 PST 2022
jmorse created this revision.
jmorse added reviewers: Orlando, StephenTozer.
Herald added a subscriber: hiraditya.
jmorse requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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. The kind of change is demonstrated in the modifications to the spill-nospill.ll test below.
There's a slight risk from the fact that we don't terminate stack variable location at the end of the function, when the stack pointer gets modified a lot during frame destruction. The policy we follow right now [0] is that we expect consumers to know stack locations aren't valid outside the function body. Doing this more often increases the damage if a consumer doesn't have the same expectations. CC @dblaikie , who had an opinion on this last time it came up.
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 .
[0] https://github.com/llvm/llvm-project/blob/843d1eda18c3a7a700fe0858748e175727498d21/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp#L502
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D120732
Files:
llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
llvm/test/DebugInfo/MIR/InstrRef/livedebugvalues_recover_clobbers.mir
Index: llvm/test/DebugInfo/MIR/InstrRef/livedebugvalues_recover_clobbers.mir
===================================================================
--- llvm/test/DebugInfo/MIR/InstrRef/livedebugvalues_recover_clobbers.mir
+++ llvm/test/DebugInfo/MIR/InstrRef/livedebugvalues_recover_clobbers.mir
@@ -76,6 +76,17 @@
; 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
Index: llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
===================================================================
--- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -1539,11 +1539,6 @@
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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120732.412081.patch
Type: text/x-patch
Size: 1753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220301/31f46f3b/attachment.bin>
More information about the llvm-commits
mailing list