glsl: Optimize lrp(x, 0, a) into x - (x * a).
authorMatt Turner <mattst88@gmail.com>
Mon, 24 Feb 2014 23:00:45 +0000 (15:00 -0800)
committerMatt Turner <mattst88@gmail.com>
Fri, 28 Feb 2014 18:36:12 +0000 (10:36 -0800)
Helps one program in shader-db:

instructions in affected programs:     96 -> 92 (-4.17%)

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/opt_algebraic.cpp

index 28f95a4..778638c 100644 (file)
@@ -570,6 +570,8 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
          return ir->operands[0];
       } else if (is_vec_zero(op_const[0])) {
          return mul(ir->operands[1], ir->operands[2]);
+      } else if (is_vec_zero(op_const[1])) {
+         return add(ir->operands[0], neg(mul(ir->operands[0], ir->operands[2])));
       }
       break;