[PATCH] Peephole optimization causes different code generation at "-O2 -g" and "-O2".

Katya Romanova Katya_Romanova at playstation.sony.com
Thu Feb 13 15:38:26 PST 2014


kromanova added you to the CC list for the revision "Peephole optimization causes different code generation at "-O2 -g" and "-O2".".

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.


http://llvm-reviews.chandlerc.com/D2728

Files:
  test/CodeGen/X86/dbg-changes-codegen-1.ll
  test/CodeGen/X86/dbg-changes-codegen-2.ll
  lib/CodeGen/PeepholeOptimizer.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2728.3.patch
Type: text/x-patch
Size: 18073 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140213/7e4425f0/attachment.bin>


More information about the llvm-commits mailing list