Fix for BZ #18590: http://llvm.org/bugs/show_bug.cgi?id=18590
This code review is for the bug fix in peephole optimization that folds a load which defines one vreg into the one and only use of that vreg. With debug info, a DBG_VALUE that referenced the vreg considered to be a use, preventing the optimization.
The fix is to ignore DBG_VALUE's during the optimization, and undef a DBG_VALUE that references a vreg that gets removed.
The main issue is how to update the DBG_VALUE properly. I looked at all calls of isDebugValue() to see what is typically done. There is at least one case that does each of the following:
- rewrite the debug info (this was during inlining to change the vreg)
- delete it (happens in tail duplication)
- undef's it, by setting register to %noreg (in eliminate dead insns)
Looking at those also showed that most optimization happily just skip any DBG_VALUE while iterating over insns. Which is what I do in this fix.
I also looked at all calls to MachineInstr::eraseFromParent() to see how other code dealt with DBG_VALUE's when deleting an instruction. In most cases it did nothing. Presumably because the live debug variable pass will clean it up. I tested a fix that does nothing to the DBG_VALUE for this peephole case and it does get set to %noreg by the live debug variable pass.
In the end this fix requires 3 simple changes:
- skip DBG_VALUE's while iterating over instructions
- only consider NonDBG uses when checking whether a def has a single use
- undef any DBG_VALUE's that use the vreg getting folded.
Fix by Trevor Smigiel.