[Mesa-dev] [PATCH 3/3] i965/fs: Add a pass to commute immediates.

Kenneth Graunke kenneth at whitecape.org
Fri Mar 13 16:23:41 PDT 2015


i965 hardware doesn't allow immediates in src0.  Normally, we have to
promote that to a separate instruction.  To avoid this, we can flip
the operands of any commutative instructions.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/drivers/dri/i965/brw_fs.cpp | 22 ++++++++++++++++++++++
 src/mesa/drivers/dri/i965/brw_fs.h   |  1 +
 2 files changed, 23 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 8702ea8..f53584a 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -2527,6 +2527,27 @@ fs_visitor::opt_algebraic()
 }
 
 bool
+fs_visitor::opt_commute_immediates()
+{
+   bool progress = false;
+
+   foreach_block_and_inst(block, fs_inst, inst, cfg) {
+      if (inst->is_commutative() && inst->src[0].file == IMM) {
+         if (inst->src[1].file != IMM) {
+            fs_reg temp = inst->src[1];
+            inst->src[1] = inst->src[0];
+            inst->src[0] = temp;
+            progress = true;
+         } else {
+            perf_debug("shader contains an instruction with two immediates");
+         }
+      }
+   }
+
+   return progress;
+}
+
+bool
 fs_visitor::opt_register_renaming()
 {
    bool progress = false;
@@ -3714,6 +3735,7 @@ fs_visitor::optimize()
       OPT(remove_duplicate_mrf_writes);
 
       OPT(opt_algebraic);
+      OPT(opt_commute_immediates);
       OPT(opt_cse);
       OPT(opt_copy_propagate);
       OPT(opt_peephole_predicated_break);
diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index 7716529..09df02b 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -218,6 +218,7 @@ public:
    void calculate_live_intervals();
    void calculate_register_pressure();
    bool opt_algebraic();
+   bool opt_commute_immediates();
    bool opt_redundant_discard_jumps();
    bool opt_cse();
    bool opt_cse_local(bblock_t *block);
-- 
2.2.2



More information about the mesa-dev mailing list