Mesa (master): glsl: Optimize scalar all_equal/any_nequal into equal/ nequal.

Matt Turner mattst88 at kemper.freedesktop.org
Fri Dec 5 17:50:08 UTC 2014


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

Author: Matt Turner <mattst88 at gmail.com>
Date:   Fri Aug 22 14:30:38 2014 -0700

glsl: Optimize scalar all_equal/any_nequal into equal/nequal.

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 at anholt.net>

---

 src/glsl/opt_algebraic.cpp |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 430f5cb..c4f883b 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -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 */




More information about the mesa-commit mailing list