[Mesa-dev] [PATCH 22/23] i965/fs: Don't do AND-instead-of-SEL optimization for a comparison of an expression with zero

Ian Romanick idr at freedesktop.org
Fri Mar 20 13:58:22 PDT 2015


From: Ian Romanick <ian.d.romanick at intel.com>

Shader-db results:

Ivy Bridge (0x0166):
total instructions in shared programs: 6274041 -> 6273868 (-0.00%)
instructions in affected programs:     30913 -> 30740 (-0.56%)
helped:                                121

No change on any other platform or with NIR.  Weird.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 37 +++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index f1e9fb5..cc28808 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -685,6 +685,40 @@ fs_visitor::emit_interpolate_expression(ir_expression *ir)
    }
 }
 
+static bool
+is_comparison_of_expression_with_zero(ir_rvalue *ir)
+{
+   ir_expression *const cmp = ir->as_expression();
+
+   if (cmp == NULL)
+      return false;
+
+   switch (cmp->operation) {
+   case ir_binop_less:
+   case ir_binop_greater:
+   case ir_binop_lequal:
+   case ir_binop_gequal:
+   case ir_binop_equal:
+   case ir_binop_nequal:
+      break;
+   default:
+      return false;
+   }
+
+   const ir_constant *const op_const[2] = {
+      cmp->operands[0]->as_constant(),
+      cmp->operands[1]->as_constant()
+   };
+
+   const ir_expression *const op_expr[2] = {
+      cmp->operands[0]->as_expression(),
+      cmp->operands[1]->as_expression()
+   };
+
+   return (op_const[0] != NULL && op_const[0]->is_zero() && op_expr[1] != NULL) ||
+      (op_const[1] != NULL && op_const[1]->is_zero() && op_expr[0] != NULL);
+}
+
 void
 fs_visitor::visit(ir_expression *ir)
 {
@@ -725,7 +759,8 @@ fs_visitor::visit(ir_expression *ir)
        * ir_unop_b2f and ir_unop_b2i are implemented.
        */
       ir_constant *const false_result = ir->operands[2]->as_constant();
-      if (brw->gen >= 6 && false_result && false_result->is_zero()) {
+      if (brw->gen >= 6 && false_result && false_result->is_zero() &&
+          !is_comparison_of_expression_with_zero(ir->operands[0])) {
          ir->operands[0]->accept(this);
          op[0] = this->result;
          ir->operands[1]->accept(this);
-- 
2.1.0



More information about the mesa-dev mailing list