<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Feb 2, 2017 at 9:18 AM Stephen Rogers <<a href="mailto:stephen.rogers@movidius.com">stephen.rogers@movidius.com</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">Turns out this was being caused by our own pre-register allocation instruction scheduler. The debug information caused calls to <span style="font-family:monospace,monospace" class="gmail_msg">LiveIntervals::handleMove</span> to be ordered slightly differently. This change meant a range of slot indexes had to be renumbered.<br class="gmail_msg"><br class="gmail_msg"></div>I'm curious though. Despite the order of instructions being identical in both cases, the weights assigned to virtual registers was changed by the different slot indexes. Why does the register allocator use the absolute values of the slot indexes in this way when they don't seem to correspond directly to the structure of the incoming code?<br class="gmail_msg"></div></div></div></blockquote><div><br></div><div>Can't say I know too much about the register allocator or how that might be happening (so I added Lang Hames who might have some context).</div><div> </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"><br class="gmail_msg"></div>Thanks,<br class="gmail_msg"></div>Stephen<br class="gmail_msg"></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On 2 February 2017 at 17:03, Robinson, Paul via llvm-dev <span dir="ltr" class="gmail_msg"><<a href="mailto:llvm-dev@lists.llvm.org" class="gmail_msg" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div link="blue" vlink="purple" lang="EN-US" class="gmail_msg">
<div class="m_5247960679566044972m_680020821152319458WordSection1 gmail_msg">
<p class="MsoNormal gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="gmail_msg">I remember running into cases where –g introduces pseudo-instructions for .cfi-* directives, and these become scheduling barriers and therefore affect the final
code a bit; I don't remember anything about register allocation being affected, though.<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="gmail_msg">A reproducer would be awesome.<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="gmail_msg">--paulr<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg"><a name="m_5247960679566044972_m_680020821152319458__MailEndCompose" class="gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt" class="gmail_msg">
<div class="gmail_msg">
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in" class="gmail_msg">
<p class="MsoNormal gmail_msg"><b class="gmail_msg"><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" class="gmail_msg">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" class="gmail_msg"> llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" class="gmail_msg" target="_blank">llvm-dev-bounces@lists.llvm.org</a>]
<b class="gmail_msg">On Behalf Of </b>Adrian Prantl via llvm-dev<br class="gmail_msg">
<b class="gmail_msg">Sent:</b> Thursday, February 02, 2017 8:46 AM<br class="gmail_msg">
<b class="gmail_msg">To:</b> David Blaikie<br class="gmail_msg">
<b class="gmail_msg">Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" class="gmail_msg" target="_blank">llvm-dev@lists.llvm.org</a><br class="gmail_msg">
<b class="gmail_msg">Subject:</b> Re: [llvm-dev] Register allocator behaves differently when compiling with and without -g<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p>
</div>
</div><div class="gmail_msg"><div class="m_5247960679566044972h5 gmail_msg">
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<div class="gmail_msg">
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt" class="gmail_msg">
<div class="gmail_msg">
<p class="MsoNormal gmail_msg">On Feb 2, 2017, at 8:20 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="gmail_msg" target="_blank">dblaikie@gmail.com</a>> wrote:<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</div>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<div class="gmail_msg">
<div class="gmail_msg">
<p class="MsoNormal gmail_msg">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 class="gmail_msg">
<br class="gmail_msg">
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.<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</div>
</div>
</blockquote>
<div class="gmail_msg">
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
</div>
<div class="gmail_msg">
<p class="MsoNormal gmail_msg">Just wanted to add, if you are not able to fix it yourself, it would also be helpful if you could file a PR with a testcase.<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</div>
<div class="gmail_msg">
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
</div>
<div class="gmail_msg">
<p class="MsoNormal gmail_msg">-- adrian<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</div>
<p class="MsoNormal gmail_msg"><br class="gmail_msg">
<br class="gmail_msg">
<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<div class="gmail_msg">
<div class="gmail_msg">
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<div class="gmail_msg">
<div class="gmail_msg">
<p class="MsoNormal gmail_msg">On Thu, Feb 2, 2017 at 8:18 AM Stephen Rogers via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="gmail_msg" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in" 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">
<div class="gmail_msg">
<p class="MsoNormal gmail_msg" style="margin-bottom:12.0pt">Hi all,<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</div>
<p class="MsoNormal gmail_msg" style="margin-bottom:12.0pt">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 class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg"><span style="font-family:"Courier New"" class="gmail_msg">DBG_VALUE</span></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:"Courier New"" class="gmail_msg"><br class="gmail_msg">
<span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg">32B %vreg29<def> = LDImm 1; REG1:%vreg29</span><br class="gmail_msg">
<span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg">36B %vreg44<def> = LDImm 1103515245; REG1:%vreg44</span><br class="gmail_msg">
<span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg">40B %vreg143:vsub32_1<def,read-undef> = LDImm 0; REG2:%vreg143</span><br class="gmail_msg">
<span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg">44B %vreg68<def> = LDImm 12345; REG1:%vreg68</span><br class="gmail_msg">
<span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg">64B %vreg143:vsub32_0<def> = COPY %vreg143:vsub32_1; REG2:%vreg143</span><br class="gmail_msg">
<span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg">72B %vreg78<def> = LDImm 32; REG1:%vreg78</span></span><u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</div>
<p class="MsoNormal gmail_msg" style="margin-bottom:12.0pt"><span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg"><span style="font-family:"Arial","sans-serif"" class="gmail_msg">But when I specify -g, this becomes:</span></span><span style="font-family:"Arial","sans-serif"" class="gmail_msg"><br class="gmail_msg">
<br class="gmail_msg">
</span><span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg"><span style="font-family:"Courier New"" class="gmail_msg">32B %vreg29<def> = LDImm 1; REG1:%vreg29 dbg:path/to/source:9:34 @[ path/to/source:25:13 ]</span></span><span style="font-family:"Courier New"" class="gmail_msg"><br class="gmail_msg">
<span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg">36B %vreg44<def> = LDImm 1103515245; REG1:%vreg44 dbg:path/to/source:9:34 @[ path/to/source:25:13 ]</span><br class="gmail_msg">
<span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg"><span style="color:red;background:white" class="gmail_msg">44B</span> %vreg143:vsub32_1<def,read-undef> = LDImm 0; REG2:%vreg143</span><br class="gmail_msg">
<span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg"><span style="color:red" class="gmail_msg">48B</span> %vreg68<def> = LDImm 12345; REG1:%vreg68 dbg:path/to/source:9:47 @[ path/to/source:25:13 ]</span><br class="gmail_msg">
<span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg"><span style="color:red" class="gmail_msg">56B</span> %vreg143:vsub32_0<def> = COPY %vreg143:vsub32_1; REG2:%vreg143</span><br class="gmail_msg">
<span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg"><span style="color:red" class="gmail_msg">60B</span> %vreg78<def> = LDImm 32; REG1:%vreg78</span></span><u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</div>
<p class="MsoNormal gmail_msg" style="margin-bottom:12.0pt"><span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg"><span style="font-family:"Arial","sans-serif"" class="gmail_msg">This change seems to affect the weight assigned to the
</span></span><span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg"><span style="font-family:"Courier New"" class="gmail_msg">LiveIntervals</span></span><span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg"><span style="font-family:"Arial","sans-serif"" class="gmail_msg"> for each virtual register which in turn changes the allocation order.</span></span><u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</div>
<p class="MsoNormal gmail_msg" style="margin-bottom:12.0pt"><span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg"><span style="font-family:"Arial","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?</span></span><u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</div>
<p class="MsoNormal gmail_msg"><span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg"><span style="font-family:"Arial","sans-serif"" class="gmail_msg">Thanks,</span></span><u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</div>
<p class="MsoNormal gmail_msg"><span class="m_5247960679566044972m_680020821152319458gmailmsg gmail_msg"><span style="font-family:"Arial","sans-serif"" class="gmail_msg">Stephen</span></span><u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</div>
<p class="MsoNormal gmail_msg">_______________________________________________<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" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</blockquote>
</div>
</div>
</div>
</div>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
</div></div></div>
</div>
</div>
<br class="gmail_msg">_______________________________________________<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">
<br class="gmail_msg"></blockquote></div><br class="gmail_msg"></div>
</blockquote></div></div>