<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">AArch64AddressTypePromotion.cpp does a fair bit of work to help make these things work out well. It could probably be generalized for non-AArch64 targets as per the comment in the file header.<div><br><div><blockquote type="cite"><div>On Jun 26, 2014, at 10:42 AM, Sanjay Patel <<a href="mailto:spatel@rotateright.com">spatel@rotateright.com</a>> wrote:</div><br class="Apple-interchange-newline"><div><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div>Cool HW trick. :)<br></div>Are those 'sxtw' ops free?<span class="Apple-converted-space"> </span><br><br></div></div></blockquote><div><br></div><div>That’ll depend on the details of the micro architecture. I don’t know what is typical.</div><br><blockquote type="cite"><div><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I have to look at the HW manuals again, but I don't think x86-64 has that capability.<br></div><div class="gmail_extra" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br><br><div class="gmail_quote">On Thu, Jun 26, 2014 at 11:23 AM, James Molloy<span class="Apple-converted-space"> </span><span dir="ltr"><<a href="mailto:james.molloy@arm.com" target="_blank">james.molloy@arm.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div link="blue" vlink="purple" lang="EN-GB"><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">Hi Sanjay,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">The behaviour I’m talking about I’ve actually pinned down to CodeGenPrepare not working too well with ISA’s that don’t have a good scaled load. I have a patch to fix it that is going through performance testing now.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">Your testcase seems specific to x86 – for aarch64 we get the rather spiffy:<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">_Z3fooPii:                              // @_Z3fooPii<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">// BB#0:                                // %entry<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">               <span class="Apple-converted-space"> </span>add        w8, w1, #1              // =1<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">               <span class="Apple-converted-space"> </span>add        w9, w1, #2              // =2<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">               <span class="Apple-converted-space"> </span>ldr           w8, [x0, w8, sxtw #2]<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">               <span class="Apple-converted-space"> </span>ldr           w9, [x0, w9, sxtw #2]<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">               <span class="Apple-converted-space"> </span>add        w8, w9, w8<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">               <span class="Apple-converted-space"> </span>str           w8, [x0, w1, sxtw #2]<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">               <span class="Apple-converted-space"> </span>ret<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">The sext can be matched as part of the addressing mode for AArch64 – maybe it’s something in codegenprepare for x86 going awry?<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">Cheers,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">James<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><div style="border-style: none none none solid; border-left-color: blue; border-left-width: 1.5pt; padding: 0cm 0cm 0cm 4pt;"><div><div style="border-style: solid none none; border-top-color: rgb(181, 196, 223); border-top-width: 1pt; padding: 3pt 0cm 0cm;"><p class="MsoNormal"><b><span lang="EN-US" style="font-size: 10pt; font-family: Tahoma, sans-serif;">From:</span></b><span lang="EN-US" style="font-size: 10pt; font-family: Tahoma, sans-serif;"><span class="Apple-converted-space"> </span>Sanjay Patel [mailto:<a href="mailto:spatel@rotateright.com" target="_blank">spatel@rotateright.com</a>]<span class="Apple-converted-space"> </span><br><b>Sent:</b><span class="Apple-converted-space"> </span>26 June 2014 18:11<br><b>To:</b><span class="Apple-converted-space"> </span>Manjunath DN<br><b>Cc:</b><span class="Apple-converted-space"> </span>James Molloy;<span class="Apple-converted-space"> </span><a href="mailto:llvmdev@cs.uiuc.edu" target="_blank">llvmdev@cs.uiuc.edu</a></span></p><div><div class="h5"><br><b>Subject:</b><span class="Apple-converted-space"> </span>Re: [LLVMdev] Contributing the Apple ARM64 compiler backend<u></u><u></u></div></div><div><br class="webkit-block-placeholder"></div></div></div><div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p><div><div><p class="MsoNormal">>> We've also seen similar instances where multiple registers are used to compute very similar<br>>> addresses (such as x+0 and x+4!) and this increases register pressure.<br><br>I don't have an ARM enabled build of the tools to test with, but I suspect what I'm seeing here:<br><a href="http://llvm.org/bugs/show_bug.cgi?id=20134" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=20134</a><u></u><u></u></p></div><p class="MsoNormal"> <u></u><u></u></p><div><p class="MsoNormal">...would also be bad on AArch64.<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">On Wed, Jun 25, 2014 at 8:58 PM, Manjunath DN <<a href="mailto:manjunath.dn@gmail.com" target="_blank">manjunath.dn@gmail.com</a>> wrote:<u></u><u></u></p><div><div><p class="MsoNormal">HI James,<u></u><u></u></p></div><div><p class="MsoNormal">Thanks for your reply and hints on what can be done for the Aarch64 backend optimization for llvm<u></u><u></u></p></div><div><p class="MsoNormal">We have SPEC license and v8 hardware. So I will start looking into it<u></u><u></u></p></div><div><p class="MsoNormal">warm regards<u></u><u></u></p></div><div><p class="MsoNormal">Manjunath<u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div></div><div><div><p class="MsoNormal" style="margin-bottom: 12pt;"><u></u> <u></u></p><div><p class="MsoNormal">On Wed, Jun 25, 2014 at 8:42 PM, James Molloy <<a href="mailto:james.molloy@arm.com" target="_blank">james.molloy@arm.com</a>> wrote:<u></u><u></u></p><p class="MsoNormal" style="margin-bottom: 12pt;">Hi Manjunath,<br><br>At the time of writing that status we had only done our initial analysis.<br>This was done without real hardware and attempted to identify poor code<br>sequences but we were unable to quantify how much effect this would actually<br>have.<br><br>Since then we've done more analysis using Cortex-A57 and Cortex-A53 on an<br>internal development platform.<br><br>For SPEC, we are between 10% and 0% behind GCC on 9 benchmarks, and 25%<br>ahead on one benchmark. Most benchmarks are less than 5% behind GCC.<br><br>Because of the licencing of SPEC, I have to be quite restricted in what I<br>say and I can't give any numbers - sorry about that.<br><br>We are focussing on Cortex-A57, and the things we've identified so far are:<br> <span class="Apple-converted-space"> </span>* The CSEL instruction behaves worse than the equivalent branch structure<br>in at least one benchmark. In an out of order core, select-like instructions<br>are going to be slower than their branched equivalent if the branch is<br>predictable due to CSEL having two dependencies.<br><br> <span class="Apple-converted-space"> </span>* Redundant calculations inside if conditions. We've seen:<br>   <span class="Apple-converted-space"> </span>1. "if (a[x].b < c[y].d || a[x].e > c[y].f)" - the calculations of a[x]<br>and c[y] are repeated, when they are common. We've also seen similar<br>instances where multiple registers are used to compute very similar<br>addresses (such as x+0 and x+4!) and this increases register pressure.<br>   <span class="Apple-converted-space"> </span>2. "if (a < 0 && b == c || a > 0 && b == d)" - the first comparison of<br>'a' against zero is done twice, when the flag results of the first<br>comparison could be used for the second comparison.<br><br> <span class="Apple-converted-space"> </span>* For a loop such as "for (i = 0; i < n; ++i)<br>{do_something_with(&x[i]);}", GCC is using &x[i] as the loop induction<br>variable where LLVM uses i and performs the calculation &x[i] on every<br>iteration. This only creates one more add instruction but the loop we see it<br>in only has 5 or so instructions.<br><br> <span class="Apple-converted-space"> </span>* The inline heuristics are way behind GCC's. If we crank the inline<br>threshold up to 1000, we can remove a 6.5% performance regression from one<br>benchmark entirely.<br><br> <span class="Apple-converted-space"> </span>* We're generating (due to SLP vectorizer and a DAG combine) loads into Q<br>registers when merging consecutive loads. This is bad, because there are no<br>callee-saved Q registers! So if the live range crosses a function call, it<br>will have to be immediately spilled again.  This can be easily fixed by<br>using load-pair instructions instead. I have a patch to fix this.<br><br>The list above is non-exhaustive and only contains things that we think may<br>affect multiple benchmarks or real-world code.<br><br>I've also noticed:<br> <span class="Apple-converted-space"> </span>* Our inline memcpy expansion pass is emitting "LDR q0, [..]; STR q0,<br>[..]" pairs, which is less than ideal on A53. If we switched to emitting<br>"LDP x0, x1, [..]; STP x0, x1, [..]", we'd get around 30% better inline<br>memcpy performance on A53. A57 seems to deal well with the LDR q sequence.<br><br>I'm sorry I'm unable to provide code samples for most of the issues found so<br>far - this is an artefact of them having come from SPEC. Trivial examples do<br>not always show the same behaviour, and as we're still investigating we<br>haven't yet been able to reduce most of these to an anonymisable testcase.<br><br>Hope this helps, but doubt it does,<br><br>James<br><br>> -----Original Message-----<br>> From:<span class="Apple-converted-space"> </span><a href="mailto:llvmdev-bounces@cs.uiuc.edu" target="_blank">llvmdev-bounces@cs.uiuc.edu</a><span class="Apple-converted-space"> </span>[mailto:<a href="mailto:llvmdev-bounces@cs.uiuc.edu" target="_blank">llvmdev-bounces@cs.uiuc.edu</a>] On<br>> Behalf Of Manjunath N<br>> Sent: 24 June 2014 10:45<br>> To:<span class="Apple-converted-space"> </span><a href="mailto:llvmdev@cs.uiuc.edu" target="_blank">llvmdev@cs.uiuc.edu</a><br>> Subject: Re: [LLVMdev] Contributing the Apple ARM64 compiler backend<br>><br>><br>><br>> Eric Christopher <echristo <at><span class="Apple-converted-space"> </span><a href="http://gmail.com/" target="_blank">gmail.com</a>> writes:<br>><br>> ><br>> > > The big pain issues I see merging from ARM64 to AArch64 are:<br>> > > 1.      Apple have created a fairly complete scheduling model already<br>> for<br>> > > ARM64, and we'd have to merge the partial? model in AArch64 and<br>> theirs.<br>> We<br>> > > risk regressing performance on Apple's targets here, and we can't<br>> determine<br>> > > ourselves whether we have or not. This is not ideal.<br>> > > 2.      Porting over the DAG-to-DAG optimizations and any other<br>> > > optimizations that rely on the tablegen layout will be very tricky.<br>> > > 3.      The conditional compare pass is fairly comprehensive - we'd<br>> have<br>> to<br>> > > port that over or rewrite it and that would be a lot of work.<br>> > > 4.      A very quick analysis last night indicated that ARM64 has<br>> > > implemented just under half of the optimizations we discovered<br>> opportunities<br>> > > for in SPEC and EEMBC. That's a fairly comprehensive number of<br>> > > optimizations, and they won't all be easy to port.<br>> Eric,<br>> You mention that there a quite a few  optimization opportunities in SPEC<br>> 2000/ EEMBC.<br>> I am looking to optimize the Aarch64 backend. Could you please let me know<br>> the big optimizations possible?<br>><br>><br>><br>> _______________________________________________<br>> LLVM Developers mailing list<br>><span class="Apple-converted-space"> </span><a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a><span class="Apple-converted-space"> </span>       <span class="Apple-converted-space"> </span><a href="http://llvm.cs.uiuc.edu/" target="_blank">http://llvm.cs.uiuc.edu</a><br>><span class="Apple-converted-space"> </span><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br><br><br><br><u></u><u></u></p></div><p class="MsoNormal"><br><br clear="all"><u></u><u></u></p></div><p class="MsoNormal"><span style="color: rgb(136, 136, 136);">--<span class="Apple-converted-space"> </span><u></u><u></u></span></p><div><p class="MsoNormal"><span style="color: rgb(136, 136, 136);">=========================================<br>warm regards,<br>Manjunath DN<u></u><u></u></span></p></div></div><p class="MsoNormal" style="margin-bottom: 12pt;"><br>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a><span class="Apple-converted-space"> </span>       <span class="Apple-converted-space"> </span><a href="http://llvm.cs.uiuc.edu/" target="_blank">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><u></u><u></u></p></div><p class="MsoNormal"><br><br clear="all"><br>--<span class="Apple-converted-space"> </span><br>Sanjay Patel<br>RotateRight, LLC<br><a href="http://www.rotateright.com/" target="_blank">http://www.rotateright.com</a><u></u><u></u></p></div></div></div></div></div></div></blockquote></div><br><br clear="all"><br>--<span class="Apple-converted-space"> </span><br>Sanjay Patel<br>RotateRight, LLC<br><a href="http://www.rotateright.com/">http://www.rotateright.com</a></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">LLVM Developers mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><a href="mailto:LLVMdev@cs.uiuc.edu" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">LLVMdev@cs.uiuc.edu</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;"><span class="Apple-converted-space"> </span>        </span><a href="http://llvm.cs.uiuc.edu/" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">http://llvm.cs.uiuc.edu</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a></div></blockquote></div><br></div></body></html>