<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;" class="">Hi David,<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 1, 2015, at 3:28 PM, Xinliang David Li <<a href="mailto:xinliangli@gmail.com" class="">xinliangli@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><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;" class=""><div class="gmail_quote" 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;">On Fri, May 1, 2015 at 10:30 AM, Quentin Colombet<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:qcolombet@apple.com" target="_blank" class="">qcolombet@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><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;">Hi Wei,<br class=""><br class="">The short story is: I do not think this is the way to go.<br class=""><br class="">Now, the long story.<br class=""><br class="">I have mixed feelings on the direction of the approach. On one hand, I also think we should optimize for performance as long as register pressure is not a problem. On the other hand, the register pressure estimate at this level too rough to make any useful decisions.<br class=""></blockquote><div class=""><br class=""></div><div class="">That is a pretty strong statement (about usefulness of register pressure estimate) :)   I think it is probably reasonably good for cases where pressure is very low and very high -- and this part can be improved independently. </div></div></div></blockquote><div><br class=""></div><div>I have been extreme on my position to emphasize that the register pressure is broken right now. I am afraid we will chase improvement/regressions based on luck if we pursue in that direction without furthest evidences. Eventually we may reach something reasonable, but in the meantime the situation will be uncomfortable. I would need to do a gymnastic to keep the existing improvements while moving toward the right solution. That is why I was proposing to see how bad we are if we keep it simple first, then we can move toward a better model.</div><div><br class=""></div><div>The register pressure estimation may really make sense, but if that is the case I believe we should make it an analysis pass to at least unify what we are doing in the loop vectorizer.</div><div>Like I said the current pressure estimate is broken:</div><div>1. The estimation is based only on the number of register required to materialize the formulae, again IIRC. Therefore if it exceeds the register pressure, then yes, we will exceed the register pressure. But when we do not exceed the register pressure, then we cannot say anything since we do not consider the code in the loop body.</div><div>2. The number of registers given by the TTI is really rough. For instance, it does not account for aliasing between scalar and vector, it sees float and int as part of the same register class.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" 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 class=""><br class=""></div><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;">Your current approach illustrate this point. Indeed, IIRC NumRegs only gives you the number of registers you need to materialize the formulae, we do not consider how many register we already need in the loop or through the loop. Therefore, I believe by tweaking the body of the loop in your motivating example (i.e., adding just enough live ranges), we can bloat the register pressure with the new rating and have spill within the loop, whereas we wouldn’t with the previous rating.<br class=""></blockquote><div class=""><br class=""></div><div class="">If we don't want spills, but spills occur, then it is matter of tuning register pressure estimation -- can even be made more conservative. In fact, if we consider spills in the overall cost, we can even deliberately allow some spills to reduce overall cost (but that requires very precise pressure estimate).</div></div></div></blockquote><div><br class=""></div><div>Sure.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" 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 class=""> <br class=""></div><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;"><br class="">I also mentioned that in the related PR, but I believe the way to go is: not to care on register pressure and just rate the cost of the loop body. However, this implies the backends are able to recover from the register pressure bloat and I believe we are not quite here.<br class=""><br class=""></blockquote><div class=""><br class=""></div><div class="">The cost should include 'potential' spills due to register pressure.</div><div class=""><br class=""></div><div class=""> </div><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;">*How do we move?<br class=""><br class="">I would suggest we add an internal option to make LSR more aggressive w.r.t. to register pressure, and fix all the problems that rise in the backends. Then, we can turn that option on by default.<br class=""></blockquote><div class=""><br class=""></div><div class="">We want to generate optimal code sequence with minimal cost --- that is not equivalent to 'the most aggressive LSR'.   Do we already know possible ways to fix the problem once the damage is already made (high reg pressure …)?</div></div></div></blockquote><div><br class=""></div><div>That is the point, we do not know and to me that would be the first information we should seek to determine the best direction. My guts say we may not be able to recover and indeed a register pressure estimation would come handy, but I like facts :).</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" 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 class=""> </div><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;"><br class="">- What if other people still believe this is the right way to move?<br class=""><br class="">Like I said, I do not think this is the right way to go. Now, if other people believe it is, I would at least expect that you supply more details numbers. In particular, what are the actual numbers (not just the geometric means) and what are the regressions, why we do not care or how do we plan to fix them.<br class=""></blockquote><div class=""><br class=""></div><div class="">I suggest Wei to refactor the change in a way so that it can be turned on/off with an option. When that is ready, the community can help with the performance testing on their favorite platforms with their favorite benchmarks. It may turns out to be better for everyone, who knows :)</div></div></div></blockquote><div><br class=""></div><div>If we move toward this heuristic, I really suggest we make it a pass or utility to provide register pressure estimation at the IR level. The loop vectorizer and also probably GVN, LICM, etc. could use such information.</div><div><br class=""></div><div>Cheers,</div><div>-Quentin</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" 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 class=""><br class=""></div><div class="">David</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""> </div><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;"><br class="">Cheers,<br class="">-Quentin<br class=""><span class="im HOEnZb"><br class=""><br class="">REPOSITORY<br class=""> <span class="Apple-converted-space"> </span>rL LLVM<br class=""><br class=""><a href="http://reviews.llvm.org/D9429" target="_blank" class="">http://reviews.llvm.org/D9429</a><br class=""><br class=""></span><div class="HOEnZb"><div class="h5">EMAIL PREFERENCES<br class=""> <span class="Apple-converted-space"> </span><a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank" class="">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br class=""><br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></div></div></blockquote></div></div></blockquote></div><br class=""></div></body></html>