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).