This is an archive of the discontinued LLVM Phabricator instance.

Do not merge debug locations when sinking instructions
AbandonedPublic

Authored by dpaoliello on Aug 4 2023, 4:38 PM.

Details

Reviewers
arsenm
foad
Summary

The MachineSink pass moves instructions, it doesn't merge them, therefore it doesn't make sense for it to merge debug locations as leaving them intact will still produce accurate debug information.

Diff Detail

Event Timeline

dpaoliello created this revision.Aug 4 2023, 4:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2023, 4:38 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
dpaoliello requested review of this revision.Aug 4 2023, 4:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2023, 4:38 PM
Orlando added a subscriber: Orlando.Aug 7 2023, 2:36 AM

The result of this change is that debug locations are preserved after sinking. I think this is a situation where the docs specify that we should not preserve the source location of an instruction. Here is an excerpt from the linked doc explaining when we should preserve debug info:

A transformation should preserve the debug location of an instruction if the instruction either remains in its basic block, or if its basic block is folded into a predecessor that branches unconditionally. The APIs to use are IRBuilder, or Instruction::setDebugLoc.

And an example of when we shouldn't:

Examples of transformations for which this rule does not apply include:
LICM. E.g., if an instruction is moved from the loop body to the preheader, the rule for dropping locations applies.

To be honest I'm not sure if we should be merging locations at all (current behaviour), but it might be fine due to the following additional rule if the definition of "identical" is stretched (merging will preserve the identical parts of the source location).

In addition to the rule above, a transformation should also preserve the debug location of an instruction that is moved between basic blocks, if the destination block already contains an instruction with an identical debug location.

In short I think the current behaviour lines up with documented expectations. What are your thoughts, and do you have a reproducer where this behaviour causes problems?

arsenm added a comment.Aug 7 2023, 2:16 PM

Needs test

dpaoliello abandoned this revision.Aug 8 2023, 2:45 PM

Abandoning: I'm unable to reproduce the issue that I thought I was seeing with this. Sorry for the noise.