Mesa (master): i965/fs: Generate better code for ir_triop_csel.

Kenneth Graunke kwg at kemper.freedesktop.org
Wed Oct 22 04:12:01 UTC 2014


Module: Mesa
Branch: master
Commit: 4d34c4b5823de984fb8f0469b67c6b4be02030b2
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=4d34c4b5823de984fb8f0469b67c6b4be02030b2

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Oct 15 18:57:07 2014 -0700

i965/fs: Generate better code for ir_triop_csel.

Previously, we generated an extra CMP instruction:

   cmp.ge.f0(8)   g4<1>D          g2<0,1,0>F      0F
   cmp.nz.f0(8)   null            g4<8,8,1>D      0D
   (+f0) sel(8)   g120<1>F        g2.4<0,1,0>F    g3<0,1,0>F

The first operand is always a boolean, and we want to predicate the SEL
on that.  Rather than producing a boolean value and comparing it against
zero, we can just produce a condition code in the flag register.

Now we generate:

   cmp.ge.f0(8)    null            g2<0,1,0>F      0F
   (+f0) sel(8)    g124<1>F        g2.4<0,1,0>F    g3<0,1,0>F

total instructions in shared programs: 5473459 -> 5473253 (-0.00%)
instructions in affected programs:     6219 -> 6013 (-3.31%)

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Matt Turner <mattst88 at gmail.com>

---

 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp |   18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index 541c25a..3fc9e39 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -487,6 +487,19 @@ fs_visitor::visit(ir_expression *ir)
          return;
       break;
 
+   case ir_triop_csel:
+      ir->operands[1]->accept(this);
+      op[1] = this->result;
+      ir->operands[2]->accept(this);
+      op[2] = this->result;
+
+      emit_bool_to_cond_code(ir->operands[0]);
+
+      this->result = fs_reg(this, ir->type);
+      inst = emit(SEL(this->result, op[1], op[2]));
+      inst->predicate = BRW_PREDICATE_NORMAL;
+      return;
+
    case ir_unop_interpolate_at_centroid:
    case ir_binop_interpolate_at_offset:
    case ir_binop_interpolate_at_sample:
@@ -1023,11 +1036,6 @@ fs_visitor::visit(ir_expression *ir)
       break;
 
    case ir_triop_csel:
-      emit(CMP(reg_null_d, op[0], fs_reg(0), BRW_CONDITIONAL_NZ));
-      inst = emit(BRW_OPCODE_SEL, this->result, op[1], op[2]);
-      inst->predicate = BRW_PREDICATE_NORMAL;
-      break;
-
    case ir_unop_interpolate_at_centroid:
    case ir_binop_interpolate_at_offset:
    case ir_binop_interpolate_at_sample:




More information about the mesa-commit mailing list