This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo][InstrRef] Avoid a debug-info-affects-codegen scenarios in stack slot colouring
ClosedPublic

Authored by jmorse on Aug 24 2021, 7:18 AM.

Details

Summary

Stack slot colouring adds "weight" to slots if a non-dbg-value instruction refers to it. This, unfortunately, means that DBG_PHI instructions can have an effect on codegen. The fix is very simple, replace isDebugValue with isDebugInstr.

The test is not so simple; because the failure mode involves both weighting of locations and register allocation, it's really difficult to pin down a simple input that will replicate it. Thus, the test for this is the next best thing: an input that replicates the problem, but that is complicated. In instr-ref mode, the PHI in block 13 will get a DBG_PHI, that will then change the order in which stack slots are merged together. It doesn't actually eliminate any slots, instead it changes how they're used.

To avoid having an extremely fragile test, I've used a little bit of sed and test both modes across as small a period as possible (regalloc -> stack slot colouring). Without this patch applied, the DBG_PHI ends up referring to %stack.2, and other stores change their location.

Diff Detail

Event Timeline

jmorse created this revision.Aug 24 2021, 7:18 AM
jmorse requested review of this revision.Aug 24 2021, 7:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2021, 7:18 AM
Orlando accepted this revision.Aug 25 2021, 3:36 AM

I was worried about sed not being cross platform friendly but it appears that existing tests use it too. Out of curiosity, do you know what happens when this is run on Windows? LGTM either way.

This revision is now accepted and ready to land.Aug 25 2021, 3:36 AM

I was worried about sed not being cross platform friendly but it appears that existing tests use it too. Out of curiosity, do you know what happens when this is run on Windows? LGTM either way.

I believe Windows is expected to have the gnu command line tools available on the PATH. It gets really hard to write expressive tests otherwise.

I was worried about sed not being cross platform friendly but it appears that existing tests use it too. Out of curiosity, do you know what happens when this is run on Windows? LGTM either way.

I believe Windows is expected to have the gnu command line tools available on the PATH. It gets really hard to write expressive tests otherwise.

should we indicate that llvm/test/DebugInfo/MIR/InstrRef/* may depend on sed (in the lit config script)?

should we indicate that llvm/test/DebugInfo/MIR/InstrRef/* may depend on sed (in the lit config script)?

IMO no -- there are various other test directories (test/CodeGen/X86) for example that use sed and don't appear to declare or specify this anywhere, and I'm not sure how we would do that anyway. I think this is a known assumption of the tests; I haven't seen it written down anywhere though.

(Using perl on the RUN line would probably be too far!(

djtodoro accepted this revision.Aug 25 2021, 4:20 AM

should we indicate that llvm/test/DebugInfo/MIR/InstrRef/* may depend on sed (in the lit config script)?

IMO no -- there are various other test directories (test/CodeGen/X86) for example that use sed and don't appear to declare or specify this anywhere, and I'm not sure how we would do that anyway. I think this is a known assumption of the tests; I haven't seen it written down anywhere though.

(Using perl on the RUN line would probably be too far!(

OK, lgtm.