This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo][InstrRef] Correctly update DBG_PHIs during instruction scheduling
ClosedPublic

Authored by jmorse on Jul 23 2021, 7:13 AM.

Details

Summary

When the instruction scheduler runs, it saves debug-instructions, and when writing the instruction referencing stuff I figured that the new debug instructions should be treated the same as DBG_VALUEs. However, it turns out there's a nuance:

  • DBG_VALUEs can have their operands updated by the instruction scheduler, if it determines that the movement of an instruction changes what the DBG_VALUE refers to,
  • DBG_LABELs and other unimportant meta instructions are just ignored.

This is a feature I was unaware of, and it's great; unfortunately it causes a crash with instruction referencing, because:

  • DBG_PHIs should be treated like DBG_VALUEs, and have their operands updated,
  • DBG_INSTR_REFs should be treated like DBG_LABELs, just ignored.

This patch rectifies that: DBG_PHIs are placed in the collection of instructions that need to have their operands updated, and UpdateDbgValue now deals with DBG_PHIs too. In ScheduleDAGInstrs::buildSchedGraph, DBG_INSTR_REFs are now treated like DBG_LABELs and are ignored for instruction scheduling purposes. The modified test checks the same behaviour for DBG_VALUEs and DBG_PHIs, that when a register is changed in scheduling (rcx -> r8), both DBG_VALUEs and DBG_PHIs are updated.

(Someday I think we'll need to have the instruction scheduler become more debug-info aware, to avoid re-ordering assignments, but it is not that day).

Diff Detail

Event Timeline

jmorse created this revision.Jul 23 2021, 7:13 AM
jmorse requested review of this revision.Jul 23 2021, 7:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2021, 7:13 AM
StephenTozer accepted this revision.Jul 27 2021, 6:51 AM

Fix looks relatively trivial, test looks good, LGTM.

This revision is now accepted and ready to land.Jul 27 2021, 6:51 AM
This revision was landed with ongoing or failed builds.Jul 27 2021, 7:13 AM
This revision was automatically updated to reflect the committed changes.