This is an archive of the discontinued LLVM Phabricator instance.

[RegAllocFast] Salvage debug values when killing operands
Changes PlannedPublic

Authored by vsk on Feb 16 2018, 7:00 PM.

Details

Summary

Teach the fast register allocator to update DBG_VALUE instructions when
it reloads a vreg.

Specifically, when a machine operand can be killed, point the DBG_VALUE
uses of that operand to a replacement vreg and update LiveDbgValuesMap.

Diff Detail

Event Timeline

vsk created this revision.Feb 16 2018, 7:00 PM
vsk added a comment.Feb 16 2018, 7:13 PM

Here's what the end-to-end test looks like before and after this patch (along with https://reviews.llvm.org/D43386 applied).

Target 0: (e2e.Os.before) stopped.
(lldb) fr v
(S) s = (x = -16843010, y = "ab", z = 3.1415926540000001)
(int) x = <no location, value may have been optimized out>
(char) y1 = <no location, value may have been optimized out>
(double) z = <no location, value may have been optimized out>
Target 0: (e2e.Os.after) stopped.
(lldb) fr v
(double) z = 3.1415926540000001
(char) y1 = 'b'
(int) x = -16843010
(S) s = (x = -16843010, y = "ab", z = 3.1415926540000001)

The debug info part of this looks fine to me, it would be great if the same function could also be applied to the other register allocators.

vsk added a comment.Feb 19 2018, 12:52 PM

@aprantl thanks for the feedback, I'll take a look at whether MachineRegisterInfo is the right place for generic register allocator helpers to live.

A side note: I won't get back to this patch for a few days, as I need to take a look at Swift bugs.

lib/CodeGen/MachineRegisterInfo.cpp
582

Note: This probably shouldn't be called unless we've actually updated any uses.

lib/CodeGen/RegAllocFast.cpp
705

I think this should be:

auto &DbgUses = ...;
LiveDbgValueMap[DstVReg].append(DbgUses.begin(), DbgUses.end());
DbgUses.clear();

I still need to figure out how to get test coverage for this.

I still need to figure out how to get test coverage for this.

A debugify MIR pass :-)

Joke aside, that would probably by overkill. In practice -stop-before=regalloc and manually inserting DBG_VALUEs should be fine.

vsk updated this revision to Diff 135330.Feb 21 2018, 2:20 PM
vsk marked an inline comment as done.
vsk retitled this revision from [RegAllocFast] Salvage debug values when killing operands (WIP) to [RegAllocFast] Salvage debug values when killing operands.
vsk edited the summary of this revision. (Show Details)
vsk added a reviewer: sdesmalen.
  • Only update LiveDbgValsMap when a dbg_value has been salvaged. Test coverage for this is provided by the fission-ranges.ll test added in r325438. Prior to this update, the test would fail because extra locations were generated for the wrong spills.
  • I'd rather keep MachineRegisterInfo to things directly related to information about virtual registers (register class etc.); I don't think it's role should be to provide transformations for involving virtual registers. So I'd rather move the functionality somewhere else.
  • I'm skeptical this works as intended in the presence of control flow (= multiple uses and defs of a vreg anywhere in the control flow graph).
  • I'm not sure I completely understand what is going on here, is it looking for COPYs killing a value so it can replace the debug values with the copied value? The commit message should mention that then.
vsk planned changes to this revision.Feb 26 2018, 4:43 PM

Now that we've reverted r325438, we'll need some replacement before this patch is relevant.

  • I'd rather keep MachineRegisterInfo to things directly related to information about virtual registers (register class etc.); I don't think it's role should be to provide transformations for involving virtual registers. So I'd rather move the functionality somewhere else.

I'll look into this.

  • I'm skeptical this works as intended in the presence of control flow (= multiple uses and defs of a vreg anywhere in the control flow graph).

It sounds like this at least needs better testing. I'm not sure whether we do the right thing if there are dbg_value uses of the dying vreg before the copy.

  • I'm not sure I completely understand what is going on here, is it looking for COPYs killing a value so it can replace the debug values with the copied value? The commit message should mention that then.

Yes, I'll fix the commit message.