<div dir="ltr">The goal/intent is that debug info does not affect code generation. There are (many?) bugs. I think Apple folks (cc'd Adrian) may be looking at this a bit recently, not sure.<br><br>The fixes aren't usually too invasive (usually involve something counting instructions where it needs to skip counting debug intrinsics), if you're interested in having a go at fixing it yourself & sending a patch for review.<br><br><div class="gmail_quote"><div dir="ltr">On Thu, Feb 2, 2017 at 8:18 AM Stephen Rogers via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg">Hi all,<br class="gmail_msg"><br class="gmail_msg"></div>In several of our tests, I have noticed that the register allocator allocates to virtual registers in a different order when compiling with the clang option -g. Before entering the register allocator, the code is identical when compiling with and without -g (with the exception of "<span style="font-family:monospace,monospace" class="gmail_msg">DBG_VALUE</span>" instructions). The only difference I can see is the value assigned to the slot index for each instruction. As an example, without -g a snippet of a basic block looks like this:<br class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg"><br class="gmail_msg">32B        %vreg29<def> = LDImm 1; REG1:%vreg29<br class="gmail_msg">36B        %vreg44<def> = </span><span style="font-family:monospace,monospace" class="gmail_msg">LDImm </span><span style="font-family:monospace,monospace" class="gmail_msg">1103515245; REG1:%vreg44<br class="gmail_msg">40B        %vreg143:vsub32_1<def,read-undef> = LDImm 0; REG2:%vreg143<br class="gmail_msg">44B        %vreg68<def> = </span><span style="font-family:monospace,monospace" class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg">LDImm </span>12345; REG1:%vreg68<br class="gmail_msg">64B        %vreg143:vsub32_0<def> = COPY %vreg143:vsub32_1; REG2:%vreg143<br class="gmail_msg">72B        %vreg78<def> = </span><span style="font-family:monospace,monospace" class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg">LDImm </span>32; REG1:%vreg78<br class="gmail_msg"><br class="gmail_msg"></span></div><span style="font-family:monospace,monospace" class="gmail_msg"><font face="arial,helvetica,sans-serif" class="gmail_msg">But when I specify -g, this becomes:<br class="gmail_msg"><br class="gmail_msg"></font>32B        %vreg29<def> = </span><span style="font-family:monospace,monospace" class="gmail_msg">LDImm </span><span style="font-family:monospace,monospace" class="gmail_msg">1; </span><span style="font-family:monospace,monospace" class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg">REG1</span>:%vreg29 dbg:</span><span style="font-family:monospace,monospace" class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg">path/to/source</span>:9:34 @[ </span><span style="font-family:monospace,monospace" class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg">path/to/source</span>:25:13 ]<br class="gmail_msg">36B        %vreg44<def> = </span><span style="font-family:monospace,monospace" class="gmail_msg">LDImm </span><span style="font-family:monospace,monospace" class="gmail_msg">1103515245; </span><span style="font-family:monospace,monospace" class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg">REG1</span>:%vreg44 dbg:path/to/source:9:34 @[ path/to/source:25:13 ]<br class="gmail_msg"><span style="color:rgb(255,0,0)" class="gmail_msg"><span style="background-color:rgb(255,255,255)" class="gmail_msg">44B</span></span>        %vreg143:vsub32_1<def,read-undef> = </span><span style="font-family:monospace,monospace" class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg">LDImm </span>0; </span><span style="font-family:monospace,monospace" class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg">REG2</span>:%vreg143<br class="gmail_msg"><span style="color:rgb(255,0,0)" class="gmail_msg">48B</span>        %vreg68<def> = </span><span style="font-family:monospace,monospace" class="gmail_msg">LDImm </span><span style="font-family:monospace,monospace" class="gmail_msg">12345; </span><span style="font-family:monospace,monospace" class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg">REG1</span>:%vreg68 dbg:</span><span style="font-family:monospace,monospace" class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg">path/to/source</span>:9:47 @[ </span><span style="font-family:monospace,monospace" class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg">path/to/source</span>:25:13 ]<br class="gmail_msg"><span style="color:rgb(255,0,0)" class="gmail_msg">56B</span>        %vreg143:vsub32_0<def> = COPY %vreg143:vsub32_1; </span><span style="font-family:monospace,monospace" class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg">REG2</span>:%vreg143<br class="gmail_msg"><span style="color:rgb(255,0,0)" class="gmail_msg">60B</span>        %vreg78<def> = </span><span style="font-family:monospace,monospace" class="gmail_msg">LDImm </span><span style="font-family:monospace,monospace" class="gmail_msg">32; </span><span style="font-family:monospace,monospace" class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg">REG1</span>:%vreg78<font face="arial,helvetica,sans-serif" class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"></font></span></div><span style="font-family:monospace,monospace" class="gmail_msg"><font face="arial,helvetica,sans-serif" class="gmail_msg">This change seems to affect the weight assigned to the </font>LiveIntervals</span><span style="font-family:arial,helvetica,sans-serif" class="gmail_msg"> </span><span style="font-family:monospace,monospace" class="gmail_msg"><font face="arial,helvetica,sans-serif" class="gmail_msg">for each virtual register which in turn changes the allocation order.<br class="gmail_msg"><br class="gmail_msg"></font></span></div><span style="font-family:monospace,monospace" class="gmail_msg"><font face="arial,helvetica,sans-serif" class="gmail_msg">It would be my expectation that LLVM should generate identical code for a source file with and without debug information enabled. Is it possible we are missing some hook in our target backend that would prevent this? Or is this the expected behaviour in LLVM?<br class="gmail_msg"><br class="gmail_msg"></font></span></div><span style="font-family:monospace,monospace" class="gmail_msg"><font face="arial,helvetica,sans-serif" class="gmail_msg">Thanks,<br class="gmail_msg"></font></span></div><span style="font-family:monospace,monospace" class="gmail_msg"><font face="arial,helvetica,sans-serif" class="gmail_msg">Stephen<br class="gmail_msg"></font></span></div>
_______________________________________________<br class="gmail_msg">
LLVM Developers mailing list<br class="gmail_msg">
<a href="mailto:llvm-dev@lists.llvm.org" class="gmail_msg" target="_blank">llvm-dev@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="gmail_msg">
</blockquote></div></div>