<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Oct 11, 2019, at 9:09 AM, Davis, Alan via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">I have some machine code that looks something like:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">   </span>flag = true<br class=""><span class="Apple-tab-span" style="white-space:pre">    </span>c = call()<br class=""><span class="Apple-tab-span" style="white-space:pre">     </span>if (c)<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre">    </span>flag = false<br class=""><span class="Apple-tab-span" style="white-space:pre">   </span><span class="Apple-tab-span" style="white-space:pre">    </span>...<br class=""><span class="Apple-tab-span" style="white-space:pre">    </span>...<br class=""><span class="Apple-tab-span" style="white-space:pre">    </span>if (flag) ...<br class=""><br class="">The 'flag' variable is a Boolean value of type i1. The target has 1-bit condition registers but none are preserved across calls. So flag is spilled to memory, resulting in terrible code.<br class=""><br class="">There is no dependency between the flag=true instruction and the call, so I'd like to move it after the call. I was hoping the front end would do it via TargetTransformInfo::getCostOfKeepingLiveOverCall.  But apparently that only applies to vectorization transforms.<br class=""><br class="">The pre-RA MachineScheduler won't do it either, because scheduling regions are delimited by calls. (From MachineScheduler.cpp: "MachineScheduler does not currently support scheduling across calls.")<br class=""><br class="">Is there some standard way in the front end or codegen to make this happen?<br class=""><br class="">-Alan<br class=""></div></div></blockquote><br class=""></div><div>Well, hopefully someone else will chime in with ideas—maybe some target specific code already does this. I’ll just confirm that this case was not handled at the time the LLVM backend pipeline was designed. The intention was that global code motion across blocks, across calls, and even call reordering, to reduce register pressure would eventually be handled by an earlier pass in the machine pipeline while still in SSA.</div><div><br class=""></div><div>It is certainly possible to add MachineScheduler support to schedule across calls. Jonas prototyped it here: <a href="https://reviews.llvm.org/D15667" class="">https://reviews.llvm.org/D15667</a></div><div>But I think it's overkill just to fix register liveness issues that can easily be detected earlier.</div><div><br class=""></div><div>Since you already have the TTI hook, the fastest way to fix this might be with an IR pass (addIRPass) that just identifies these basic patterns. If the pattern isn’t obvious in IR, then a machine pass shouldn’t be that much harder.</div><div><br class=""></div><div>-Andy</div></body></html>