<div dir="ltr">Hello Quentin,<div><br></div><div>I am certainly looking to implement best what can be achieved and that will also require a cost estimation module which can address the mentioned bug. How ever I am still looking to some simpler (or less heavy)  approach than what I proposed so that whatever I implement that can be sent to upstream.</div><div><br></div><div>Sincerely,</div><div>Vivek</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 28, 2016 at 2:40 AM, Quentin Colombet <span dir="ltr"><<a href="mailto:qcolombet@apple.com" target="_blank">qcolombet@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div><div class="h5"><blockquote type="cite"><div>On Sep 26, 2016, at 10:12 AM, Hal Finkel <<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>> wrote:</div><br><div><br><hr style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote style="font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-left-width:2px;border-left-style:solid;border-left-color:rgb(16,16,255);margin-left:5px;padding-left:5px;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><b>From:<span> </span></b>"Quentin Colombet via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br><b>To:<span> </span></b>"vivek pandya" <<a href="mailto:vivekvpandya@gmail.com" target="_blank">vivekvpandya@gmail.com</a>><br><b>Cc:<span> </span></b>"llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>, "Nirav Rana" <<a href="mailto:h2015087@pilani.bits-pilani.ac.in" target="_blank">h2015087@pilani.bits-pilani.<wbr>ac.in</a>>, "Matthias Braun" <<a href="mailto:matze@braunis.de" target="_blank">matze@braunis.de</a>><br><b>Sent:<span> </span></b>Monday, September 19, 2016 1:27:10 PM<br><b>Subject:<span> </span></b>Re: [llvm-dev] [RFC] Register Rematerialization (remat) Extension<br><br>Hi Vivek,<div><br><div><blockquote><div>On Sep 19, 2016, at 11:17 AM, vivek pandya via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br><div><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 19, 2016 at 6:21 PM, James Molloy<span> </span><span dir="ltr"><<a href="mailto:james@jamesmolloy.co.uk" target="_blank">james@jamesmolloy.co.<wbr>uk</a>></span><span> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I've been looking at this myself for ARM, and came up with a much simpler solution: lower immediate materializations to a post-RA pseudo and expand the chain of materialization instructions after register allocation / remat. Remat only sees one instruction with no dependencies.</div><div><br></div><div>Did you look down this route and discount it?</div></div></blockquote><div>No actually I am not much familiar with this topic so I mostly reply on research papers available.</div><div>But your idea seems to be simple and good solution but I am not sure if this can cover every possible cases. </div></div></div></div></div></blockquote><div><br></div><div>This is the way all targets deal with simple rematerialization involving several instructions in LLVM AFAIK.</div><div><br></div><div>Basically, the target defines a pseudo instruction that encodes this sequence of instructions and expands it after register allocation. This is a case by case thing, there is no patch that can be generalized for other target.</div><div><div>For instance, look at the expansion of AArch64::<span style="font-family:Menlo;font-size:11px">MOVi64imm.</span></div><div><span style="font-family:Menlo;font-size:11px"><br></span></div></div><div>The bottom line is, our rematerialization scheme is currently limited, but I am not sure your proposal get us beyond what we already support.</div></div></div></blockquote><span style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">I might have misunderstood the proposal, but why do you say that? The problem is not limited to constants (as perhaps evidenced by Ivan Baev's talk at the 2014 dev meeting). One basic thing we should get, for example, is:</span><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">  q = ...;</span><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">  r = ...;</span><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">  for (...) {</span><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">    // complicated stuff</span><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">    foo(q, r, q - r); // should prefer to remat (q-r) here instead of spilling.</span><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div></blockquote><div><br></div></div></div><div>I agree, but this is not what Vivek is aiming at, is he?</div><div><div class="h5"><br><blockquote type="cite"><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">  }</span><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Also, this is all perhaps related to<span> </span></span><a href="https://llvm.org/bugs/show_bug.cgi?id=25373#c9" style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://llvm.org/bugs/show_<wbr>bug.cgi?id=25373#c9</a><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Thanks again,</span><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Hal</span><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote style="font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-left-width:2px;border-left-style:solid;border-left-color:rgb(16,16,255);margin-left:5px;padding-left:5px;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div><div><div></div><div><br></div><div>Cheers,</div><div>Q.</div><br><blockquote><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Do you have a patch for this? I can work on this to make it work for other architectures for which this will be beneficial.</div><div><br></div><div>Sincerely,</div><div>Vivek</div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>Cheers,</div><div><br></div><div>James</div></div><div><div><br><div class="gmail_quote"><div dir="ltr">On Wed, 14 Sep 2016 at 02:43 Gerolf Hoflehner via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote><div>On Sep 12, 2016, at 10:14 AM, Andrew Trick via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br><div><div style="word-wrap:break-word"><br><div><blockquote><div>On Sep 12, 2016, at 8:51 AM, vivek pandya via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br><div><div dir="ltr"><div><br></div><div>1 ) As LLVM MI is already in SSA form before reg allocation so for LLVM I think it does not require to build SSA graph and converting it back after optimization completed as mentioned in [1]</div><div><br></div><div>2 ) We would like to add a pass similar to SCCP.cpp (Sparse Conditional Constant</div><div>Propagation based on Wegman and Zadeck's work<span> </span><a href="http://dl.acm.org/citation.cfm?id=103136" target="_blank">http://dl.acm.org/<wbr>citation.cfm?id=103136</a>) as desribed in [1]. This pass will be scheduled to run before register allocation.</div><div><br></div><div>3 ) Output of the pass added in Step 2 will be a Map of def to instructions pointers (instructions which can be used to remat the given live range). The map will contain live ranges which is due to single instruction and multiple instructions.</div></div></div></blockquote><div><br></div>LiveIntervals maintains a quasi-SSA form via VNInfo. It does not allow efficient def-use queries, but use-def is there, which is all that you should need.</div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div>I also only see a narrow and specific remat cost problem in the example: is it cheaper is issue a  chain of instructions rather than a fill? And for this a use-def is sufficient.</div></div><div style="word-wrap:break-word"><div><br><blockquote><div><div style="word-wrap:break-word"><div><br></div><div>It would be great to have better remat during regalloc, but please try to avoid building additional state that needs to be maintained.</div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div>You proposed a fairly complex scheme. The question then is always is it worth it? To answer that question you would need to investigate and break down the current remat problems (spills but should remat, remat but should spill, should remat at a different location, etc) eg. for the llvm test suite, and show that your algorithms solves the most important ones.</div></div><div style="word-wrap:break-word"><div><br><div><br></div><br><blockquote><div><div style="word-wrap:break-word"><div><br></div><div>-Andy</div><div><br><blockquote><div><div dir="ltr"><div><br></div><div>4 ) The remat APIs defined in LiveRangeEdit.cpp will use analysis from the Map</div><div>when a spill is required for RA.</div><div><br></div><div>5 ) The remat transformation APIs like rematerializeAt() will be teached to remat</div><div>live ranges with multiple instructions too.</div><div><br></div><div>6 ) A cost analysis will be require to decide between remat and spill. This should be based on at least two factors register pressure and spill cost</div><div><br></div><div>Few points:</div><div>--------------</div><div>* The analysis pass to be addes as per (2) will use target specific information</div><div>from TargetInstrInfo.cpp as the current remat infrastructure uses.</div><div><br></div><div>* This approach will not be on demand as the current approach is (i.e remat specific</div><div>code will be executed only if there is a spill) so the pass in (2) can be an</div><div>overhead so we may want it to enable only for higher level of optimization.</div><div><br></div><div>* Will it be possible to use existing SCCP.cpp code with few modification to lattice</div><div>and related mathematical operation so that it can serve both purpose?</div><div><br></div><div>* No changes in current register allocators or spill framework will be required</div><div>because remat entry point will be LiveRangeEdit.</div><div><br></div><div>Any other way with less overhead is always welcomed.</div><div>Please help us developing a plan to implement this.</div><div><br></div><div>Hoping for comments!</div><div><br></div><div>Sincerely,</div><div>Vivek</div><div><br></div></div>______________________________<wbr>_________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br></div></blockquote></div><br></div>______________________________<wbr>_________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br></div></blockquote></div></div>______________________________<wbr>_________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br></blockquote></div></div></div></blockquote></div><br></div></div>______________________________<wbr>_________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br></div></blockquote></div><br></div><br>______________________________<wbr>_________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br></blockquote><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">--<span> </span></span><br style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span name="x"></span>Hal Finkel<br>Lead, Compiler Technology and Programming Languages<br>Leadership Computing Facility<br>Argonne National Laboratory</div></div></blockquote></div></div></div><br></div></blockquote></div><br></div>