glsl: Optimize scalar all_equal/any_nequal into equal/nequal.
authorMatt Turner <mattst88@gmail.com>
Fri, 22 Aug 2014 21:30:38 +0000 (14:30 -0700)
committerMatt Turner <mattst88@gmail.com>
Fri, 5 Dec 2014 17:49:42 +0000 (09:49 -0800)
Cuts an instruction from two shaders in Tesseract, by allowing the
(x+y) cmp 0 -> x cmp -y optimization to take place.

instructions in affected programs:     1198 -> 1194 (-0.33%)

Reviewed-by: Eric Anholt <eric@anholt.net>
src/glsl/opt_algebraic.cpp

index 430f5cb97902c2d8f985f77106dfea3d3143d20f..c4f883b9a8efa50e7b3044a6842ee7c98ee78b71 100644 (file)
@@ -584,6 +584,16 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       }
       break;
 
+   case ir_binop_all_equal:
+   case ir_binop_any_nequal:
+      if (ir->operands[0]->type->is_scalar() &&
+          ir->operands[1]->type->is_scalar())
+         return new(mem_ctx) ir_expression(ir->operation == ir_binop_all_equal
+                                           ? ir_binop_equal : ir_binop_nequal,
+                                           ir->operands[0],
+                                           ir->operands[1]);
+      break;
+
    case ir_binop_rshift:
    case ir_binop_lshift:
       /* 0 >> x == 0 */