<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.gmailmsg
        {mso-style-name:gmail_msg;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">A reproducer would be awesome.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> llvm-dev [mailto:llvm-dev-bounces@lists.llvm.org]
<b>On Behalf Of </b>Adrian Prantl via llvm-dev<br>
<b>Sent:</b> Thursday, February 02, 2017 8:46 AM<br>
<b>To:</b> David Blaikie<br>
<b>Cc:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm-dev] Register allocator behaves differently when compiling with and without -g<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Feb 2, 2017, at 8:20 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">-- adrian<o:p></o:p></p>
</div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">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:<o:p></o:p></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">
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Hi all,<o:p></o:p></p>
</div>
<p class="MsoNormal" 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="gmailmsg"><span style="font-family:"Courier New"">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>
<span style="font-family:"Courier New""><br>
<span class="gmailmsg">32B        %vreg29<def> = LDImm 1; REG1:%vreg29</span><br>
<span class="gmailmsg">36B        %vreg44<def> = LDImm 1103515245; REG1:%vreg44</span><br>
<span class="gmailmsg">40B        %vreg143:vsub32_1<def,read-undef> = LDImm 0; REG2:%vreg143</span><br>
<span class="gmailmsg">44B        %vreg68<def> = LDImm 12345; REG1:%vreg68</span><br>
<span class="gmailmsg">64B        %vreg143:vsub32_0<def> = COPY %vreg143:vsub32_1; REG2:%vreg143</span><br>
<span class="gmailmsg">72B        %vreg78<def> = LDImm 32; REG1:%vreg78</span></span><o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span class="gmailmsg"><span style="font-family:"Arial","sans-serif"">But when I specify -g, this becomes:</span></span><span style="font-family:"Arial","sans-serif""><br>
<br>
</span><span class="gmailmsg"><span style="font-family:"Courier New"">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""><br>
<span class="gmailmsg">36B        %vreg44<def> = LDImm 1103515245; REG1:%vreg44 dbg:path/to/source:9:34 @[ path/to/source:25:13 ]</span><br>
<span class="gmailmsg"><span style="color:red;background:white">44B</span>        %vreg143:vsub32_1<def,read-undef> = LDImm 0; REG2:%vreg143</span><br>
<span class="gmailmsg"><span style="color:red">48B</span>        %vreg68<def> = LDImm 12345; REG1:%vreg68 dbg:path/to/source:9:47 @[ path/to/source:25:13 ]</span><br>
<span class="gmailmsg"><span style="color:red">56B</span>        %vreg143:vsub32_0<def> = COPY %vreg143:vsub32_1; REG2:%vreg143</span><br>
<span class="gmailmsg"><span style="color:red">60B</span>        %vreg78<def> = LDImm 32; REG1:%vreg78</span></span><o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span class="gmailmsg"><span style="font-family:"Arial","sans-serif"">This change seems to affect the weight assigned to the
</span></span><span class="gmailmsg"><span style="font-family:"Courier New"">LiveIntervals</span></span><span class="gmailmsg"><span style="font-family:"Arial","sans-serif""> for each virtual register which in turn changes the allocation order.</span></span><o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span class="gmailmsg"><span style="font-family:"Arial","sans-serif"">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><o:p></o:p></p>
</div>
<p class="MsoNormal"><span class="gmailmsg"><span style="font-family:"Arial","sans-serif"">Thanks,</span></span><o:p></o:p></p>
</div>
<p class="MsoNormal"><span class="gmailmsg"><span style="font-family:"Arial","sans-serif"">Stephen</span></span><o:p></o:p></p>
</div>
<p class="MsoNormal">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>