[Mesa-dev] [PATCH] glsl: Optimize pow(1.0, X) --> 1.0.

Kenneth Graunke kenneth at whitecape.org
Sun Jan 5 23:13:53 PST 2014


Surprisingly, this helps one vertex shader in 3DMMES.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/glsl/opt_algebraic.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 05a5899..5e885f7 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -416,6 +416,12 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       }
       break;
 
+   case ir_binop_pow:
+      /* 1^x == 1 */
+      if (is_vec_one(op_const[0]))
+         return op_const[0];
+      break;
+
    case ir_unop_rcp:
       if (op_expr[0] && op_expr[0]->operation == ir_unop_rcp)
 	 return op_expr[0]->operands[0];
-- 
1.8.5.2



More information about the mesa-dev mailing list