<div class="gmail_quote">On Wed, Sep 14, 2011 at 10:06 AM, Jakob Stoklund Olesen <span dir="ltr"><<a href="mailto:stoklund@2pi.dk">stoklund@2pi.dk</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 class="im"><div>On Sep 14, 2011, at 9:50 AM, Chandler Carruth wrote:</div><br><blockquote type="cite"><div class="gmail_quote">On Wed, Sep 14, 2011 at 9:45 AM, Jakob Stoklund Olesen <span dir="ltr"><<a href="mailto:stoklund@2pi.dk" target="_blank">stoklund@2pi.dk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204, 204, 204);border-left-style:solid;padding-left:1ex">
Author: stoklund<br>
Date: Wed Sep 14 11:45:39 2011<br>
New Revision: 139698<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=139698&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=139698&view=rev</a><br>
Log:<br>
Hoist back-copies to the least busy dominator.<br>
<br>
When a back-copy is hoisted to the nearest common dominator, keep<br>
looking up the dominator tree for a less loopy dominator, and place the<br>
back-copy there instead.<br>
<br>
Don't do this when a single existing back-copy dominates all the others.<br>
Assume the client knows what he is doing, and keep the dominating<br>
back-copy.<br>
<br>
This prevents us from hoisting back-copies into loops in most cases.  If<br>
a value is defined in a loop with multiple exits, we may still hoist<br>
back-copies into that loop.  That is the speed/size tradeoff.<br></blockquote><div><br></div><div>This sounds quite cool; testcase?</div></div></blockquote><div><br></div></div><div>I should have mentioned that this code only runs with -split-spill-mode=size.  It is not enabled by default yet.</div>
<div><br></div><div>It is quite difficult to write good test cases for these register allocator tricks.  You need to provide a function that tricks the allocator into splitting a variable around a loop with multiple exits.  Then check that the back-copies or spills are hoisted above the loop.</div>
<div><br></div><div>It is possible to find such a function, obviously, but the test case won't be very stable.  The heuristics used to decide which virtual registers are split and spilled can be quite chaotic.  That means small changes in passes before regalloc can affect it, causing the test case to fail.</div>
<div><br></div><div>We really need a way of injecting machine code into any pass in the pipeline, like opt can do with IR.</div></div></div></blockquote><div><br></div><div>I wonder if using a more "unit test" approach might work here. You could probably write some helper C++ routines that build up the various data structures directly, and immediately feed them into SplitKit and check the result. Shouldn't be hard to write helper routines to check the output concisely either.</div>
<div><br></div><div>Still, as Evan said, likely non-trivial, but might be more straightforward than a fully general injection of machine code. On the other hand, it wouldn't solve as many different problems.</div></div>