[Mesa-dev] [PATCH 05/10] glsl: Optimize min(-8, sin(x)) == -8 and similar
thomashelland90 at gmail.com
thomashelland90 at gmail.com
Mon Jul 14 15:22:34 PDT 2014
From: Thomas Helland <thomashelland90 at gmail.com>
This patch is a bit sketchy.
It only handles float-constants, otherwise it bails.
Also, ir_unop_saturate should be added here when
support for it lands in the ir.
Signed-off-by: Thomas Helland <thomashelland90 at gmail.com>
---
src/glsl/opt_algebraic.cpp | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 230fb1b..90b6cae 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -647,6 +647,43 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
break;
+ case ir_binop_min: {
+ ir_rvalue *tempExpr;
+ ir_rvalue *tempConst;
+
+ if (op_expr[0] && op_const[1]) {
+ tempExpr = ir->operands[0];
+ tempConst = ir->operands[1];
+ } else if (op_expr[1] && op_const[0]) {
+ tempExpr = ir->operands[1];
+ tempConst = ir->operands[0];
+ } else {
+ break;
+ }
+ if(tempConst->type->is_float()) {
+ float constValue = *(tempConst->constant_expression_value()->value.f);
+ switch(tempExpr->as_expression()->operation) {
+ case ir_unop_cos:
+ case ir_unop_sin:
+ case ir_unop_sign:
+ /* If we are comparing an expression bound between -1 and 1
+ * with a const >= 1 we know that const will be the largest
+ */
+ if(constValue >= 1.0f)
+ return tempExpr;
+ /* If we are comparing an expression bound between -1 and 1
+ * with a const <= -1 we know that const will be the smallest
+ */
+ if(constValue <= -1.0f)
+ return tempConst;
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ }
+
case ir_unop_rcp:
if (op_expr[0] && op_expr[0]->operation == ir_unop_rcp)
return op_expr[0]->operands[0];
--
2.0.0
More information about the mesa-dev
mailing list