This is an archive of the discontinued LLVM Phabricator instance.

[NFC][DebugInfo][RemoveDIs] Use moveBeforePreserving when transforms intend to move dbg.values
ClosedPublic

Authored by jmorse on Jun 9 2023, 6:57 AM.

Details

Summary

As outlined in my proposal for how to get rid of debug intrinsics [0], we need to distinguish in optimisation passes when a pass /intends/ for move instructions to remain in their original order. It's the difference between moving a single instruction because we're hoisting it out of it's original position, and moving a single instruction as part of moving/copying an entire block from one place to another, all in order. This semantic difference has an effect on debug-info, and it needs to be accounted for when we remove debug intrinsics.

The patch just replaces a few calls to moveBefore with calls to moveBeforePreserving -- and the latter just calls the former, so it's all NFC right now. A future patch will add an implementation of moveBeforePreserving that takes action to correctly preserve debug-info, but that's tightly coupled with our non-instruction debug-info representation. This patch just shows how invasive the changes are.

There are, as it transpires, very few places where this makes a difference.

Not adding reviewers for now as I'd like to group all these changes, so that we talk about how they should be tested.

[0] https://discourse.llvm.org/t/rfc-instruction-api-changes-needed-to-eliminate-debug-intrinsics-from-ir/68939

Diff Detail

Event Timeline

jmorse created this revision.Jun 9 2023, 6:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2023, 6:57 AM
jmorse requested review of this revision.Jun 9 2023, 6:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2023, 6:57 AM

The mechanical change itself LGTM.

A future patch will add an implementation of moveBeforePreserving that takes action to correctly preserve debug-info, but that's tightly coupled with our non-instruction debug-info representation. This patch just shows how invasive the changes are.

Is this patch purely illustrative or will it more or less be landed as is, with the implementation coming later?

I'm not sure exactly what the current status of the testing discussion is but it does seem like it'd be easier to add lit tests if the implementation came first, before updating call sites. OTOH if unittests are sufficient coverage for the moveBeforePreserving changes it doesn't matter as much.

llvm/include/llvm/IR/Instruction.h
139

Could be worth adding a comment explaining the intended semantics?

jmorse updated this revision to Diff 555860.Sep 5 2023, 7:19 AM

Add an explanatory comment as to what moveBeforePreserving is for, and the fact that it's part of the "RemoveDIs" project.

In terms of landing this, as it's an NFC change I was hoping we could just put it in as-is, it's simply changing the spelling of a function call in various places (and also reduces the rebasing / maintenance churn of our stack of patches). In terms of testing the functional changes when they arrive, it forms a part of the overall problem first suggested at D151419: there is no overall approach because we don't have comprehensive testing of the compiler in the first place. Once we've got a bot running RemoveDIs/DDD over the test suite transparently though, we'll have coverage over all the parts of the compiler that are currently tested at least.

Orlando accepted this revision.Sep 5 2023, 7:27 AM

LGTM

This revision is now accepted and ready to land.Sep 5 2023, 7:27 AM
jmorse updated this revision to Diff 556168.Sep 7 2023, 9:06 AM

Actually, the majority of the base patch is questioned, so I've pulled getStableDebugLoc into this one, if that's alright. (It's a debug-intrinsic-skipping getDebugLoc).

Blurgh, attached the wrong patch to the wrong review ^^^. Will land the approved patch, which will change this back to what it's supposed to be.

jmorse closed this revision.Sep 8 2023, 3:46 AM

Closed by rG4427407a2936, where I also pasted the wrong Phab number X_X. Haven't landed a patch in months, I'm way out of practice.