[Mesa-dev] [PATCH 2/2] i965/fs: Try to avoid generating extra MOVs to do saturates.

Eric Anholt eric at anholt.net
Tue Mar 13 14:37:50 PDT 2012


shader-db results:
Total instructions: 212648 -> 206044
614/1246 programs affected (49.3%)
178350 -> 171746 instructions in affected programs (3.7% reduction)
---
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index eb129ce..e7af75b 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -172,12 +172,30 @@ fs_visitor::try_emit_saturate(ir_expression *ir)
    if (!sat_val)
       return false;
 
+   fs_inst *pre_inst = (fs_inst *) this->instructions.get_tail();
+
    sat_val->accept(this);
    fs_reg src = this->result;
 
-   this->result = fs_reg(this, ir->type);
-   fs_inst *inst = emit(BRW_OPCODE_MOV, this->result, src);
-   inst->saturate = true;
+   fs_inst *last_inst = (fs_inst *) this->instructions.get_tail();
+
+   /* If the last instruction from our accept() didn't generate our
+    * src, generate a saturated MOV
+    */
+   if (last_inst == pre_inst ||
+       last_inst->predicated ||
+       last_inst->force_uncompressed ||
+       last_inst->force_sechalf ||
+       !src.equals(&last_inst->dst) ||
+       last_inst->regs_written() != 1) {
+      this->result = fs_reg(this, ir->type);
+      fs_inst *inst = emit(BRW_OPCODE_MOV, this->result, src);
+      inst->saturate = true;
+   } else {
+      last_inst->saturate = true;
+      this->result = src;
+   }
+
 
    return true;
 }
-- 
1.7.9.1



More information about the mesa-dev mailing list