<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<font size="-1" face="Courier New, Courier, monospace">Hi all,<br>
<br>
thinking a bit harder about the problem I now believe the problem is not fixable<br>
by changing scheduling and my patch <a class="moz-txt-link-freetext" href="https://reviews.llvm.org/D68639">
https://reviews.llvm.org/D68639</a> gets<br>
obsolete.<br>
<br>
Since a cfi instruction describes the stack with respect to all stack altering<br>
instructions that precede it, no such stack altering instruction is allowed to<br>
be scheduled below the cfi instruction. But the opposite is also true: No stack<br>
altering instruction is allowed to be move above a cfi instruction.<br>
<br>
Cfi instructions have to act as barriers for stack altering instructions. The <br>
current situation let's them act as barriers for all instructions, my patch <br>
relaxed this behaviour too much.<br>
<br>
By letting cfi instructions act as barriers for stack altering instructions<br>
only, scheduling could be improved. However, the generated assembly would still<br>
be different to the one without cfi instructions (e.g. non-debug case).<br>
<br>
Next plan: Postpone insertion of cfi instructions after machine scheduling. This<br>
is option 3 in the original email and will probably require target specific<br>
code. I'll keep you updated.<br>
<br>
    David<br>
<br>
</font><br>
<div class="moz-cite-prefix">On 07/10/2019 18:31, Vedant Kumar wrote:<br>
</div>
<blockquote type="cite" cite="mid:B2ECFB6F-27E8-435D-BA0B-658E5FEE6CB6@apple.com">
<br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Oct 5, 2019, at 7:03 AM, David Tellenbach <<a href="mailto:David.Tellenbach@arm.com" class="" moz-do-not-send="true">David.Tellenbach@arm.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div style="font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration: none;
              font-family: Calibri, Arial, Helvetica, sans-serif;
              font-size: 12pt;" class="">
Hi Vedant,</div>
<div style="font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration: none;
              font-family: Calibri, Arial, Helvetica, sans-serif;
              font-size: 12pt;" class="">
<br class="">
</div>
<div style="font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration: none;
              font-family: Calibri, Arial, Helvetica, sans-serif;
              font-size: 12pt;" class="">
thanks for your answer and sorry for the late response. </div>
<blockquote style="font-family: Helvetica; font-size: 14px;
              font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; orphans:
              auto; text-align: start; text-indent: 0px; text-transform:
              none; white-space: normal; widows: auto; word-spacing:
              0px; -webkit-text-size-adjust: auto;
              -webkit-text-stroke-width: 0px; text-decoration: none;
              border-left-width: 3px; border-left-style: solid;
              border-color: rgb(200, 200, 200); padding-left: 1ex;
              margin-left: 0.8ex; color: rgb(102, 102, 102);" class="">
<div style="font-family: Calibri, Arial, Helvetica,
                sans-serif; font-size: 12pt;" class="">
<span style="color: rgb(32, 31, 30); font-family:
                  "Segoe UI", "Segoe UI Web (West
                  European)", "Segoe UI", -apple-system,
                  system-ui, Roboto, "Helvetica Neue",
                  sans-serif; font-size: 15px; background-color:
                  rgb(255, 255, 255); display: inline !important;" class="">It
 seems like D68076 might not address the underlying issue here (e.g. it probably doesn't improve the situation for projects using `-g -fno-unwind-tables`?).</span></div>
</blockquote>
<div style="font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration: none;
              font-family: Calibri, Arial, Helvetica, sans-serif;
              font-size: 12pt;" class="">
Yes, D68075 is a somewhat conservative patch that aligns the behaviour on AArch64 (for GNU targets) that leads to consistent generated assembly. As you said it does not help if unwind tables are explicitly disabled (`-fno-unwind-tables`). It is a conservative
 patch since it decreases scheduling potential (due to smaller scheduling regions) for the non-debug case but fixes the bug of generating inconsistent assembly. </div>
<blockquote style="font-family: Helvetica; font-size: 14px;
              font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; orphans:
              auto; text-align: start; text-indent: 0px; text-transform:
              none; white-space: normal; widows: auto; word-spacing:
              0px; -webkit-text-size-adjust: auto;
              -webkit-text-stroke-width: 0px; text-decoration: none;
              border-left-width: 3px; border-left-style: solid;
              border-color: rgb(200, 200, 200); padding-left: 1ex;
              margin-left: 0.8ex; color: rgb(102, 102, 102);" class="">
<div style="font-family: Calibri, Arial, Helvetica,
                sans-serif; font-size: 12pt;" class="">
<span style="color: rgb(32, 31, 30); font-family:
                  "Segoe UI", "Segoe UI Web (West
                  European)", "Segoe UI", -apple-system,
                  system-ui, Roboto, "Helvetica Neue",
                  sans-serif; font-size: 15px; background-color:
                  rgb(255, 255, 255); display: inline !important;" class="">Would
 you mind elaborating a bit on your proposals to delay/change CFI instruction insertion? In particular, it'd help to hear a bit about how CFI instructions are inserted today (is some of it done by CFIInstrInserter, and the rest by target-specific frame lowering
 code?).</span><br class="">
</div>
</blockquote>
<div style="font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration: none;
              font-family: Calibri, Arial, Helvetica, sans-serif;
              font-size: 12pt;" class="">
CFI instructions are inserted during target specific frame lowering, the CFIInstrInserter is only run on X86 targets and seems to verify the correctness of CFI instructions after the got inserted during X86 frame lowering.</div>
<div style="font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration: none;
              font-family: Calibri, Arial, Helvetica, sans-serif;
              font-size: 12pt;" class="">
<br class="">
</div>
<div style="font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration: none;
              font-family: Calibri, Arial, Helvetica, sans-serif;
              font-size: 12pt;" class="">
Regarding the 3 possible roadmaps to solve the issue (see my first email) I currently think 3 (changing instruction scheduling such that CFI instructions are scheduled together with stack altering instructions) is the most promising one because it wouldn't
 require targets specific changes. Since e.g. X86 or if I remember correctly also AArch64 on Darwin targets insert CFI instructions in both, debug and non-debug mode, solution 3 would increase scheduling potential for these targets.</div>
<div style="font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration: none;
              font-family: Calibri, Arial, Helvetica, sans-serif;
              font-size: 12pt;" class="">
<br class="">
</div>
<div style="font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration: none;
              font-family: Calibri, Arial, Helvetica, sans-serif;
              font-size: 12pt;" class="">
To summarize: D68075 would align non-debug mode with debug mode and therefore potentially *decrease* scheduling potential. Solution 3 would align debug mode with non-debug mode (in terms of instruction scheduling) and therefore *increase* scheduling potential.</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>Thanks for breaking things down so clearly. My gut instinct would be to push for changes that make scheduling decisions the same modulo CFI instructions, but I really don't know how much work that entails, or if it would pay for its own complexity. OTOH
 the "option 1" patch you have is an immediate fix.</div>
<div><br class="">
</div>
<div>CC'ing some folks who probably have more experience working with CFI/scheduling than me (+ Amara, Adam, Florian).</div>
<div><br class="">
</div>
<div>vedant</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div style="font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration: none;
              font-family: Calibri, Arial, Helvetica, sans-serif;
              font-size: 12pt;" class="">
 </div>
<div style="font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration: none;
              font-family: Calibri, Arial, Helvetica, sans-serif;
              font-size: 12pt;" class="">
<br class="">
</div>
<div style="font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration: none;
              font-family: Calibri, Arial, Helvetica, sans-serif;
              font-size: 12pt;" class="">
    David</div>
<hr tabindex="-1" style="caret-color: rgb(0, 0, 0);
              font-family: Helvetica; font-size: 14px; font-style:
              normal; font-variant-caps: normal; font-weight: normal;
              letter-spacing: normal; text-align: start; text-indent:
              0px; text-transform: none; white-space: normal;
              word-spacing: 0px; -webkit-text-stroke-width: 0px;
              text-decoration: none; display: inline-block; width:
              1708.125px;" class="">
<span style="caret-color: rgb(0, 0,
              0); font-family: Helvetica; font-size: 14px; font-style:
              normal; font-variant-caps: normal; font-weight: normal;
              letter-spacing: normal; text-align: start; text-indent:
              0px; text-transform: none; white-space: normal;
              word-spacing: 0px; -webkit-text-stroke-width: 0px;
              text-decoration: none; float: none; display: inline
              !important;" class=""></span>
<div id="divRplyFwdMsg" dir="ltr" style="caret-color: rgb(0,
              0, 0); font-family: Helvetica; font-size: 14px;
              font-style: normal; font-variant-caps: normal;
              font-weight: normal; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<font style="font-size: 11pt;" class="" face="Calibri, sans-serif"><b class="">From:</b><span class="Apple-converted-space"> </span><a href="mailto:vsk@apple.com" class="" moz-do-not-send="true">vsk@apple.com</a> <<a href="mailto:vsk@apple.com" class="" moz-do-not-send="true">vsk@apple.com</a>>
 on behalf of Vedant Kumar <<a href="mailto:vedant_kumar@apple.com" class="" moz-do-not-send="true">vedant_kumar@apple.com</a>><br class="">
<b class="">Sent:</b><span class="Apple-converted-space"> </span>30 September 2019 20:50<br class="">
<b class="">To:</b><span class="Apple-converted-space"> </span>David Tellenbach <<a href="mailto:David.Tellenbach@arm.com" class="" moz-do-not-send="true">David.Tellenbach@arm.com</a>><br class="">
<b class="">Cc:</b><span class="Apple-converted-space"> </span><a href="mailto:paul.robinson@sony.com" class="" moz-do-not-send="true">paul.robinson@sony.com</a> <<a href="mailto:paul.robinson@sony.com" class="" moz-do-not-send="true">paul.robinson@sony.com</a>>;
<a href="mailto:llvm-dev@lists.llvm.org" class="" moz-do-not-send="true">llvm-dev@lists.llvm.org</a> <<a href="mailto:llvm-dev@lists.llvm.org" class="" moz-do-not-send="true">llvm-dev@lists.llvm.org</a>>; nd <<a href="mailto:nd@arm.com" class="" moz-do-not-send="true">nd@arm.com</a>>;
 Tim Northover <<a href="mailto:tnorthover@apple.com" class="" moz-do-not-send="true">tnorthover@apple.com</a>>; Ahmed Bougacha <<a href="mailto:abougacha@apple.com" class="" moz-do-not-send="true">abougacha@apple.com</a>><br class="">
<b class="">Subject:</b><span class="Apple-converted-space"> </span>Re: [llvm-dev] [AArch64] Generated assembly differs depending on whether debug information is generated or not</font>
<div class=""> </div>
</div>
<div class="" style="caret-color: rgb(0, 0, 0); font-family:
              Helvetica; font-size: 14px; font-style: normal;
              font-variant-caps: normal; font-weight: normal;
              letter-spacing: normal; text-align: start; text-indent:
              0px; text-transform: none; white-space: normal;
              word-spacing: 0px; -webkit-text-stroke-width: 0px;
              text-decoration: none; word-wrap: break-word; line-break:
              after-white-space;">
Hi David,
<div class=""><br class="">
</div>
<div class="">Thanks for looking into this.</div>
<div class=""><br class="">
</div>
<div class="">It seems like D68076 might not address the underlying issue here (e.g. it probably doesn't improve the situation for projects using `-g -fno-unwind-tables`?).</div>
<div class=""><br class="">
</div>
<div class="">Would you mind elaborating a bit on your proposals to delay/change CFI instruction insertion? In particular, it'd help to hear a bit about how CFI instructions are inserted today (is some of it done by CFIInstrInserter, and the rest by target-specific
 frame lowering code?).</div>
<div class=""><br class="">
</div>
<div class="">best,</div>
<div class="">vedant<br class="">
<div class=""><br class="">
<blockquote type="cite" class="">
<div class="">On Sep 26, 2019, at 6:57 AM, David Tellenbach via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="" moz-do-not-send="true">llvm-dev@lists.llvm.org</a>> wrote:</div>
<br class="x_Apple-interchange-newline">
<div class=""><span class="" style="font-family:
                        Helvetica; font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none; float: none; display:
                        inline !important;">Hi
 Paul,</span><br class="" style="font-family: Helvetica; font-size: 14px;
                        font-style: normal; font-variant-caps: normal;
                        font-weight: normal; letter-spacing: normal;
                        text-align: start; text-indent: 0px;
                        text-transform: none; white-space: normal;
                        word-spacing: 0px; background-color: rgb(255,
                        255, 255); text-decoration: none;">
<br class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none;">
<span class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none; float: none; display:
                        inline !important;">thanks
 for your comments.</span><br class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none;">
<blockquote type="cite" class="" style="font-family: Helvetica; font-size: 14px;
                        font-style: normal; font-variant-caps: normal;
                        font-weight: normal; letter-spacing: normal;
                        text-align: start; text-indent: 0px;
                        text-transform: none; white-space: normal;
                        word-spacing: 0px; background-color: rgb(255,
                        255, 255); text-decoration: none;">
<span class="" style="font-size: 11pt; font-family:
                          Calibri, sans-serif; color: rgb(31, 73, 125);">This is PR37240 (<a href="https://bugs.llvm.org/show_bug.cgi?id=37240" class="" style="color: purple;
                            text-decoration: underline;" moz-do-not-send="true">https://bugs.llvm.org/show_bug.cgi?id=37240</a>). 
 I suspect this problem affects all targets; your patch D68076 would address it only for AArch64.  Although I would suggest you do some careful measurements to determine the runtime performance effect, to decide whether this is acceptable.</span></blockquote>
<span class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none; float: none; display:
                        inline !important;">Yes,
 in principle the problem that instruction scheduling is dependent on the presence of cfi instruction should affect more targets than AArch64. However, this does not imply that all of these targets produce inconsistent assembly depending on debug information.</span><br class="" style="font-family: Helvetica; font-size: 14px;
                        font-style: normal; font-variant-caps: normal;
                        font-weight: normal; letter-spacing: normal;
                        text-align: start; text-indent: 0px;
                        text-transform: none; white-space: normal;
                        word-spacing: 0px; background-color: rgb(255,
                        255, 255); text-decoration: none;">
<br class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none;">
<blockquote type="cite" class="" style="font-family: Helvetica; font-size: 14px;
                        font-style: normal; font-variant-caps: normal;
                        font-weight: normal; letter-spacing: normal;
                        text-align: start; text-indent: 0px;
                        text-transform: none; white-space: normal;
                        word-spacing: 0px; background-color: rgb(255,
                        255, 255); text-decoration: none;">
<span class="" style="font-size: 11pt; font-family:
                          Calibri, sans-serif; color: rgb(31, 73, 125);">The more complete approach in your steps 2 + 3 would solve this for all targets, assuming the solution did not have to be very target-specific. 
 This would benefit the entire community.</span></blockquote>
<span class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none; float: none; display:
                        inline !important;">At
 least 2. would require a lot of target dependent changes because the insertion of cfi instructions would have to be moved from target specific frame lowering into an (probably again target specific) insertion pass.</span><br class="" style="font-family:
                        Helvetica; font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none;">
<br class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none;">
<span class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none; float: none; display:
                        inline !important;">   
     David</span><br class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none;">
<br class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none;">
<div class="x_moz-cite-prefix" style="font-family:
                        Helvetica; font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none;">
On 26/09/2019 13:55,<span class="x_Apple-converted-space"> </span><a class="x_moz-txt-link-abbreviated" href="mailto:paul.robinson@sony.com" style="color: purple; text-decoration:
                          underline;" moz-do-not-send="true">paul.robinson@sony.com</a><span class="x_Apple-converted-space"> </span>wrote:<br class="">
</div>
<blockquote type="cite" class="" style="font-family: Helvetica; font-size: 14px;
                        font-style: normal; font-variant-caps: normal;
                        font-weight: normal; letter-spacing: normal;
                        text-align: start; text-indent: 0px;
                        text-transform: none; white-space: normal;
                        word-spacing: 0px; background-color: rgb(255,
                        255, 255); text-decoration: none;">
<div class="x_WordSection1">
<div class="" style="margin: 0in 0in 0.0001pt;
                            font-size: 12pt; font-family: "Times
                            New Roman", serif;">
<span class="" style="font-size: 11pt; font-family:
                              Calibri, sans-serif; color: rgb(31, 73,
                              125);">Hi David,</span></div>
<div class="" style="margin: 0in 0in 0.0001pt;
                            font-size: 12pt; font-family: "Times
                            New Roman", serif;">
<span class="" style="font-size: 11pt; font-family:
                              Calibri, sans-serif; color: rgb(31, 73,
                              125);"> </span></div>
<div class="" style="margin: 0in 0in 0.0001pt;
                            font-size: 12pt; font-family: "Times
                            New Roman", serif;">
<span class="" style="font-size: 11pt; font-family:
                              Calibri, sans-serif; color: rgb(31, 73,
                              125);">This is PR37240 (<a href="https://bugs.llvm.org/show_bug.cgi?id=37240" class="" style="color: purple;
                                text-decoration: underline;" moz-do-not-send="true">https://bugs.llvm.org/show_bug.cgi?id=37240</a>). 
 I suspect this problem affects all targets; your patch D68076 would address it only for AArch64.  Although I would suggest you do some careful measurements to determine the runtime performance effect, to decide whether this is acceptable.</span></div>
<div class="" style="margin: 0in 0in 0.0001pt;
                            font-size: 12pt; font-family: "Times
                            New Roman", serif;">
<span class="" style="font-size: 11pt; font-family:
                              Calibri, sans-serif; color: rgb(31, 73,
                              125);"> </span></div>
<div class="" style="margin: 0in 0in 0.0001pt;
                            font-size: 12pt; font-family: "Times
                            New Roman", serif;">
<span class="" style="font-size: 11pt; font-family:
                              Calibri, sans-serif; color: rgb(31, 73,
                              125);">The more complete approach in your steps 2 + 3 would solve this for all targets, assuming the solution
 did not have to be very target-specific.  This would benefit the entire community.</span></div>
<div class="" style="margin: 0in 0in 0.0001pt;
                            font-size: 12pt; font-family: "Times
                            New Roman", serif;">
<span class="" style="font-size: 11pt; font-family:
                              Calibri, sans-serif; color: rgb(31, 73,
                              125);">--paulr</span></div>
<div class="" style="margin: 0in 0in 0.0001pt;
                            font-size: 12pt; font-family: "Times
                            New Roman", serif;">
<a name="x__MailEndCompose" class="" moz-do-not-send="true"><span class="" style="font-size: 11pt; font-family:
                                Calibri, sans-serif; color: rgb(31, 73,
                                125);"> </span></a></div>
<div class="" style="border-style: none none
                            none solid; border-left-width: 1.5pt;
                            border-left-color: blue; padding: 0in 0in
                            0in 4pt;">
<div class="">
<div class="" style="border-style: solid
                                none none; border-top-width: 1pt;
                                border-top-color: rgb(181, 196, 223);
                                padding: 3pt 0in 0in;">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<b class=""><span class="" style="font-size: 10pt;
                                      font-family: Tahoma, sans-serif;">From:</span></b><span class="" style="font-size: 10pt;
                                    font-family: Tahoma, sans-serif;"><span class="x_Apple-converted-space"> </span>llvm-dev
 [<a class="x_moz-txt-link-freetext" href="mailto:llvm-dev-bounces@lists.llvm.org" style="color: purple;
                                      text-decoration: underline;" moz-do-not-send="true">mailto:llvm-dev-bounces@lists.llvm.org</a>]<span class="x_Apple-converted-space"> </span><b class="">On
 Behalf Of<span class="x_Apple-converted-space"> </span></b>David Tellenbach via llvm-dev<br class="">
<b class="">Sent:</b><span class="x_Apple-converted-space"> </span>Thursday, September 26, 2019 5:57 AM<br class="">
<b class="">To:</b><span class="x_Apple-converted-space"> </span>llvm-dev<br class="">
<b class="">Cc:</b><span class="x_Apple-converted-space"> </span>nd<br class="">
<b class="">Subject:</b><span class="x_Apple-converted-space"> </span>[llvm-dev] [AArch64] Generated assembly differs depending on whether debug information is generated or not</span></div>
</div>
</div>
<div class="" style="margin: 0in 0in
                              0.0001pt; font-size: 12pt; font-family:
                              "Times New Roman", serif;">
 </div>
<div class="">
<div class="" style="margin: 0in 0in
                                0.0001pt; font-size: 12pt; font-family:
                                "Times New Roman", serif;">
<span class="">Hi,</span><span class="" style="font-family: Calibri,
                                  sans-serif;"></span></div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="" style="font-family: Calibri,
                                    sans-serif;"> </span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">we at Arm have noticed that assembly can differ when compiling for AArch64</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">depending on whether debug information is generated or not.</span><span class="" style="font-family:
                                    Calibri, sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="" style="font-family: Calibri,
                                    sans-serif;"> </span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">The issue is reproducible for the following small example compiled with `-O1`</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">for `aarch64-arm-linux-gnu`:</span><span class="" style="font-family:
                                    Calibri, sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="" style="font-family: Calibri,
                                    sans-serif;"> </span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">    a() {</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">      b(a);</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">      for (;;)</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">        c("", b);</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">    }</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="" style="font-family: Calibri,
                                    sans-serif;"> </span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">The reason for the difference is that AArch64 frame lowering emits CFI</span><span class="" style="font-family:
                                    Calibri, sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">instructions if debug information is enabled but not if not. CFI instructions</span><span class="" style="font-family:
                                    Calibri, sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">act as scheduling boundaries during instruction scheduling and therefore lead to</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">differing scheduling regions and an overall different instruction scheduling.</span><span class="" style="font-family:
                                    Calibri, sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="" style="font-family: Calibri,
                                    sans-serif;"> </span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">We see several ways to fix the issue and would welcome comments on this:</span><span class="" style="font-family:
                                    Calibri, sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="" style="font-family: Calibri,
                                    sans-serif;"> </span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">  1. Enabling unwind tables by default for AArch64: By enabling unwind tables</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">     by default CFI instructions will be inserted in both, debug and non-debug</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">     mode. This should lead to smaller scheduling regions and probably to less</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">     scheduling potential.</span><span class="" style="font-family:
                                    Calibri, sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="" style="font-family: Calibri,
                                    sans-serif;"> </span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">     However, I've measured the average size of scheduling regions for randomly</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">     generated programs with and without default unwind tables and found an</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">     average difference of 0.5 to 1 instruction. Other architectures such as x86</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">     do exactly this and therefore don't face the issue.</span><span class="" style="font-family:
                                    Calibri, sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="" style="font-family: Calibri,
                                    sans-serif;"> </span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">     The following patch on Phabricator introduces the said change:</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">                   <span class="x_Apple-converted-space"> </span><a class="x_moz-txt-link-freetext" href="https://reviews.llvm.org/D68076" style="color: purple;
                                      text-decoration: underline;" moz-do-not-send="true">https://reviews.llvm.org/D68076</a></span><span class="" style="font-family:
                                    Calibri, sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="" style="font-family: Calibri,
                                    sans-serif;"> </span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">  2. Postpone insertion of CFI instructions until after instruction scheduling.</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">     This would require a new pass running after instruction scheduling that  </span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">     inserts CFI instructions if needed. The downside I see is increased</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">     compile-time and probably some code duplication with frame lowering.</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="" style="font-family: Calibri,
                                    sans-serif;"> </span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">  3. Change instruction scheduling such that CFI instructions get tied together</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">     with relevant instructions in such a way that they get scheduled together.</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">     If this could work it would probably the cleanest solution.</span><span class="" style="font-family:
                                    Calibri, sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="" style="font-family: Calibri,
                                    sans-serif;"> </span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">To summarize:</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">1. would make scheduling in the non-debug case behave like in the</span><span class="" style="font-family:
                                    Calibri, sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">debug case and therefore probably cost some scheduling potential. However, it</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">would be by far the most easy to implement. 2. + 3. would probably lead to</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">better scheduling but seem to be more complex to implement.</span><span class="" style="font-family:
                                    Calibri, sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="" style="font-family: Calibri,
                                    sans-serif;"> </span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">Comments and additional ideas are welcome.</span><span class="" style="font-family:
                                    Calibri, sans-serif;"></span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="" style="font-family: Calibri,
                                    sans-serif;"> </span></div>
</div>
<div class="">
<div class="" style="margin: 0in 0in
                                  0.0001pt; font-size: 12pt;
                                  font-family: "Times New
                                  Roman", serif;">
<span class="">    David</span><span class="" style="font-family: Calibri,
                                    sans-serif;"></span></div>
</div>
<div class="" style="margin: 0in 0in
                                0.0001pt; font-size: 12pt; font-family:
                                "Times New Roman", serif;">
<span class="" style="font-family: Calibri,
                                  sans-serif;"> </span></div>
</div>
</div>
</div>
</blockquote>
<br class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none;">
<span class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none; float: none; display:
                        inline !important;">_______________________________________________</span><br class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none;">
<span class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none; float: none; display:
                        inline !important;">LLVM
 Developers mailing list</span><br class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none;">
<span class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none; float: none; display:
                        inline !important;"><a href="mailto:llvm-dev@lists.llvm.org" class="" moz-do-not-send="true">llvm-dev@lists.llvm.org</a></span><br class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none;">
<span class="" style="font-family: Helvetica;
                        font-size: 14px; font-style: normal;
                        font-variant-caps: normal; font-weight: normal;
                        letter-spacing: normal; text-align: start;
                        text-indent: 0px; text-transform: none;
                        white-space: normal; word-spacing: 0px;
                        background-color: rgb(255, 255, 255);
                        text-decoration: none; float: none; display:
                        inline !important;"><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" class="" moz-do-not-send="true">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></span></div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</blockquote>
<br>
</body>
</html>