<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Apr 10, 2017 at 5:23 PM, Francisco Jerez <span dir="ltr"><<a href="mailto:currojerez@riseup.net" target="_blank">currojerez@riseup.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The individual branches of an if/else/endif construct will be executed<br>
some unknown number of times between 0 and 1 relative to the parent<br>
block.  Use some factor in between as weight while approximating the<br>
cost of spill/fill instructions within a conditional if-else branch.<br>
This favors spilling registers used within conditional branches which<br>
are likely to be executed less frequently than registers used at the<br>
top level.<br>
<br>
Improves the framerate of the SynMark2 OglCSDof benchmark by ~1.9x on<br>
my SKL GT4e.  Should have a comparable effect on other platforms.  No<br>
significant regressions.<br></blockquote><div><br></div><div>Nice!<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
 src/intel/compiler/brw_fs_reg_<wbr>allocate.cpp | 19 ++++++++++++++-----<br>
 1 file changed, 14 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/src/intel/compiler/brw_fs_<wbr>reg_allocate.cpp b/src/intel/compiler/brw_fs_<wbr>reg_allocate.cpp<br>
index 5c6f3d4..c981d72 100644<br>
--- a/src/intel/compiler/brw_fs_<wbr>reg_allocate.cpp<br>
+++ b/src/intel/compiler/brw_fs_<wbr>reg_allocate.cpp<br>
@@ -806,7 +806,7 @@ emit_spill(const fs_builder &bld, fs_reg src,<br>
 int<br>
 fs_visitor::choose_spill_reg(<wbr>struct ra_graph *g)<br>
 {<br>
-   float loop_scale = 1.0;<br>
+   float block_scale = 1.0;<br>
    float spill_costs[this->alloc.count]<wbr>;<br>
    bool no_spill[this->alloc.count];<br>
<br>
@@ -822,23 +822,32 @@ fs_visitor::choose_spill_reg(<wbr>struct ra_graph *g)<br>
    foreach_block_and_inst(block, fs_inst, inst, cfg) {<br>
       for (unsigned int i = 0; i < inst->sources; i++) {<br>
         if (inst->src[i].file == VGRF)<br>
-            spill_costs[inst->src[i].nr] += loop_scale;<br>
+            spill_costs[inst->src[i].nr] += block_scale;<br>
       }<br>
<br>
       if (inst->dst.file == VGRF)<br>
          spill_costs[inst-><a href="http://dst.nr" rel="noreferrer" target="_blank">dst.nr</a>] += DIV_ROUND_UP(inst->size_<wbr>written, REG_SIZE)<br>
-                                      * loop_scale;<br>
+                                      * block_scale;<br>
<br>
       switch (inst->opcode) {<br>
<br>
       case BRW_OPCODE_DO:<br>
-        loop_scale *= 10;<br>
+        block_scale *= 10;<br>
         break;<br>
<br>
       case BRW_OPCODE_WHILE:<br>
-        loop_scale /= 10;<br>
+        block_scale /= 10;<br>
         break;<br>
<br>
+      case BRW_OPCODE_IF:<br>
+      case BRW_OPCODE_IFF:<br>
+         block_scale *= 0.5;<br></blockquote><div><br></div><div>Maybe 0.75 since it may or may not be uniform?  Or 0.9 for that matter.  It's all arbitrary (see also 10).  My only concern is that, if we set it too low, the compiler may decide to spill something with 4 spills over something with 2 just because it's in control-flow (or 8 vs. 2 if it's nested in a level).  In this particular shader, the spills are so deep into an if-ladder that it doesn't really matter because the compounding will make it look free regardless.<br><br></div><div>I'd like Matt or Ken's opinion in here as well but, for my part,<br><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+         break;<br>
+<br>
+      case BRW_OPCODE_ENDIF:<br>
+         block_scale /= 0.5;<br>
+         break;<br>
+<br>
       case SHADER_OPCODE_GEN4_SCRATCH_<wbr>WRITE:<br>
         if (inst->src[0].file == VGRF)<br>
             no_spill[inst->src[0].nr] = true;<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.10.2<br>
<br>
</font></span></blockquote></div><br></div></div>