<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 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle18
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.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="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><o:p> </o:p></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 #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b>From:</b> llvm-dev [mailto:llvm-dev-bounces@lists.llvm.org] <b>On Behalf Of </b>Jun Lim via llvm-dev<br><b>Sent:</b> Thursday, February 22, 2018 11:05 AM<o:p></o:p></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Hi All, <o:p></o:p></p><p class=MsoNormal>I found some cases where a spill of a live range in a block is reloaded only in one of its successors, and there is no reload in other paths through other successors. Since the spill is reloaded only in a certain path, it must be okay to sink such spill close to its reloads. In the AArch64 code below, there is a spill(x2) in the entry, but this value is reloaded only in %bb.1, not in .LBB2_32. If we sink the spill (str x2, [sp, #120]) from the entry to its successor (%bb.1), the load-from-store promotion might catch this and replace the ldr in %bb.1 with a mov instruction. As we move such spill down to its successor, we can also encourage more shrink-wrapping as well.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>.globl _mytest<o:p></o:p></p><p class=MsoNormal>// %bb.0: // %entry<o:p></o:p></p><p class=MsoNormal> sub sp, sp, #224 // =224<o:p></o:p></p><p class=MsoNormal> stp x28, x27, [sp, #128] // 8-byte Folded Spill<o:p></o:p></p><p class=MsoNormal> stp x26, x25, [sp, #144] // 8-byte Folded Spill<o:p></o:p></p><p class=MsoNormal> stp x24, x23, [sp, #160] // 8-byte Folded Spill<o:p></o:p></p><p class=MsoNormal> stp x22, x21, [sp, #176] // 8-byte Folded Spill<o:p></o:p></p><p class=MsoNormal> stp x20, x19, [sp, #192] // 8-byte Folded Spill<o:p></o:p></p><p class=MsoNormal> stp x29, x30, [sp, #208] // 8-byte Folded Spill<o:p></o:p></p><p class=MsoNormal> ldrsw x8, [x0, #4424]<o:p></o:p></p><p class=MsoNormal> sxtw x10, w2 <------------- w2 is the use of spilled value before spill.<o:p></o:p></p><p class=MsoNormal> sxtw x12, w1<o:p></o:p></p><p class=MsoNormal> madd x8, x8, x10, x12<o:p></o:p></p><p class=MsoNormal> ldr x9, [x0, #8]<o:p></o:p></p><p class=MsoNormal> add x9, x9, x8, lsl #2<o:p></o:p></p><p class=MsoNormal> ldrh w11, [x9]<o:p></o:p></p><p class=MsoNormal> ldrh w10, [x0, #16]<o:p></o:p></p><p class=MsoNormal> str x2, [sp, #120] // 8-byte Folded Spill <------------- spill !!! <o:p></o:p></p><p class=MsoNormal> cmp w11, w10<o:p></o:p></p><p class=MsoNormal> b.eq .LBB2_32<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>// %bb.1: // %if.end<o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Presumably there is a redefinition of x2 somewhere in here, otherwise it wouldn’t need to be spilled at all?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal> ldr x13, [sp, #120] // 8-byte Folded Reload <-------------- reload !!<o:p></o:p></p><p class=MsoNormal> < omitted ><o:p></o:p></p><p class=MsoNormal> :<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>.LBB2_32: // %cleanup <----- no reload from [sp, #120]<o:p></o:p></p><p class=MsoNormal> ldp x29, x30, [sp, #208] // 8-byte Folded Reload<o:p></o:p></p><p class=MsoNormal> ldp x20, x19, [sp, #192] // 8-byte Folded Reload<o:p></o:p></p><p class=MsoNormal> ldp x22, x21, [sp, #176] // 8-byte Folded Reload<o:p></o:p></p><p class=MsoNormal> ldp x24, x23, [sp, #160] // 8-byte Folded Reload<o:p></o:p></p><p class=MsoNormal> ldp x26, x25, [sp, #144] // 8-byte Folded Reload<o:p></o:p></p><p class=MsoNormal> ldp x28, x27, [sp, #128] // 8-byte Folded Reload<o:p></o:p></p><p class=MsoNormal> add sp, sp, #224 // =224<o:p></o:p></p><p class=MsoNormal> ret<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Unless there is hidden issues that prevent it from being sunk, I think such sinking should be done after RA because sinking it down during RA will extend the live range of the spilled value. Please let me know if there any hidden issue that I miss here? I may happy to hear any opinion about it.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks, <o:p></o:p></p><p class=MsoNormal>Jun<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>-- <o:p></o:p></p><p class=MsoNormal>Geoff Berry<o:p></o:p></p><p class=MsoNormal>Employee of Qualcomm Datacenter Technologies, Inc.<o:p></o:p></p><p class=MsoNormal> Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>