<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 19, 2015 at 3:31 PM, Matt Turner <span dir="ltr"><<a href="mailto:mattst88@gmail.com" target="_blank">mattst88@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">total instructions in shared programs: 5974160 -> 5959463 (-0.25%)<br>
instructions in affected programs:     1743737 -> 1729040 (-0.84%)<br>
GAINED:                                0<br>
LOST:                                  12<br>
---<br>
 src/mesa/drivers/dri/i965/Makefile.sources         |  1 +<br>
 src/mesa/drivers/dri/i965/brw_fs.cpp               |  1 +<br>
 src/mesa/drivers/dri/i965/brw_fs.h                 |  1 +<br>
 .../drivers/dri/i965/brw_fs_cmod_propagation.cpp   | 97 ++++++++++++++++++++++<br>
 4 files changed, 100 insertions(+)<br>
 create mode 100644 src/mesa/drivers/dri/i965/brw_fs_cmod_propagation.cpp<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/Makefile.sources b/src/mesa/drivers/dri/i965/Makefile.sources<br>
index 3b72955..da48455 100644<br>
--- a/src/mesa/drivers/dri/i965/Makefile.sources<br>
+++ b/src/mesa/drivers/dri/i965/Makefile.sources<br>
@@ -39,6 +39,7 @@ i965_FILES = \<br>
        brw_ff_gs_emit.c \<br>
        brw_ff_gs.h \<br>
        brw_fs_channel_expressions.cpp \<br>
+       brw_fs_cmod_propagation.cpp \<br>
        brw_fs_copy_propagation.cpp \<br>
        brw_fs.cpp \<br>
        brw_fs_cse.cpp \<br>
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
index 73d722e..994d457 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
@@ -3581,6 +3581,7 @@ fs_visitor::optimize()<br>
       OPT(opt_cse);<br>
       OPT(opt_copy_propagate);<br>
       OPT(opt_peephole_predicated_break);<br>
+      OPT(opt_cmod_propagation);<br>
       OPT(dead_code_eliminate);<br>
       OPT(opt_peephole_sel);<br>
       OPT(dead_control_flow_eliminate, this);<br>
diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h<br>
index 9c125a6..e1bc7d7 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_fs.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_fs.h<br>
@@ -539,6 +539,7 @@ public:<br>
    bool opt_peephole_sel();<br>
    bool opt_peephole_predicated_break();<br>
    bool opt_saturate_propagation();<br>
+   bool opt_cmod_propagation();<br>
    void emit_bool_to_cond_code(ir_rvalue *condition);<br>
    void emit_if_gen6(ir_if *ir);<br>
    void emit_unspill(bblock_t *block, fs_inst *inst, fs_reg reg,<br>
diff --git a/src/mesa/drivers/dri/i965/brw_fs_cmod_propagation.cpp b/src/mesa/drivers/dri/i965/brw_fs_cmod_propagation.cpp<br>
new file mode 100644<br>
index 0000000..5ba2fd6<br>
--- /dev/null<br>
+++ b/src/mesa/drivers/dri/i965/brw_fs_cmod_propagation.cpp<br>
@@ -0,0 +1,97 @@<br>
+/*<br>
+ * Copyright © 2014 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#include "brw_fs.h"<br>
+#include "brw_fs_live_variables.h"<br>
+#include "brw_cfg.h"<br>
+<br>
+/** @file brw_fs_cmod_propagation.cpp<br>
+ *<br>
+ * Implements a pass that propagates the conditional modifier from a CMP x 0.0<br>
+ * instruction into the instruction that generated x. For instance, in this<br>
+ * sequence<br>
+ *<br>
+ *    add(8)          g70<1>F    g69<8,8,1>F    4096F<br>
+ *    cmp.ge.f0(8)    null       g70<8,8,1>F    0F<br>
+ *<br>
+ * we can do the comparison as part of the ADD instruction directly:<br>
+ *<br>
+ *    add.ge.f0(8)    g70<1>F    g69<8,8,1>F    4096F<br>
+ */<br>
+<br>
+static bool<br>
+opt_cmod_propagation_local(fs_visitor *v, bblock_t *block)<br>
+{<br>
+   bool progress = false;<br>
+   int ip = block->end_ip + 1;<br>
+<br>
+   foreach_inst_in_block_reverse_safe(fs_inst, inst, block) {<br>
+      ip--;<br>
+<br>
+      if (inst->opcode != BRW_OPCODE_CMP ||<br>
+          inst->predicate != BRW_PREDICATE_NONE ||<br>
+          !inst->dst.is_null() ||<br>
+          inst->src[0].file != GRF ||<br>
+          inst->src[0].abs ||<br>
+          inst->src[0].negate ||<br>
+          !inst->src[1].is_zero())<br>
+         continue;<br>
+<br>
+      foreach_inst_in_block_reverse_starting_from(fs_inst, scan_inst, inst,<br>
+                                                  block) {<br>
+         if (scan_inst->dst.file == GRF &&<br>
+             scan_inst->dst.reg == inst->src[0].reg &&<br>
+             scan_inst->dst.reg_offset == inst->src[0].reg_offset &&<br>
+             !scan_inst->is_partial_write()) {<br></blockquote><div><br></div><div>I don't think this is quite the right condition.  We want to do the replacement under these conditions but if it's a partial write we want to break without replacement.  In other words, we want to break whenever something *may* have touched it and only consider it as a substitute for the CMP if they overwrote it entirely.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+            if (scan_inst->can_do_cmod() &&<br>
+                (scan_inst->conditional_mod == BRW_CONDITIONAL_NONE ||<br>
+                 scan_inst->conditional_mod == inst->conditional_mod)) {<br>
+               scan_inst->conditional_mod = inst->conditional_mod;<br>
+               inst->remove(block);<br>
+               progress = true;<br>
+            }<br>
+            break;<br>
+         }<br>
+<br>
+         if (scan_inst->reads_flag() || scan_inst->writes_flag())<br>
+            break;<br>
+      }<br>
+   }<br>
+<br>
+   return progress;<br>
+}<br>
+<br>
+bool<br>
+fs_visitor::opt_cmod_propagation()<br>
+{<br>
+   bool progress = false;<br>
+<br>
+   foreach_block_reverse(block, cfg) {<br>
+      progress = opt_cmod_propagation_local(this, block) || progress;<br>
+   }<br>
+<br>
+   if (progress)<br>
+      invalidate_live_intervals();<br>
+<br>
+   return progress;<br>
+}<br>
<span><font color="#888888">--<br>
2.0.4<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>