[Mesa-dev] [PATCH 22/22] glsl: Remove useless abs based on range analysis
Thomas Helland
thomashelland90 at gmail.com
Sat Jan 3 11:18:27 PST 2015
---
src/glsl/opt_minmax.cpp | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/src/glsl/opt_minmax.cpp b/src/glsl/opt_minmax.cpp
index 8cf0fe5..3d3cfff 100644
--- a/src/glsl/opt_minmax.cpp
+++ b/src/glsl/opt_minmax.cpp
@@ -80,6 +80,8 @@ public:
ir_rvalue *opt_compare(ir_expression *expr, minmax_range baserange);
+ ir_rvalue *opt_abs(ir_expression *expr, minmax_range baserange);
+
ir_rvalue *opt_undefined_behaviour(ir_expression *expr, minmax_range baserange);
void handle_rvalue(ir_rvalue **rvalue);
@@ -598,6 +600,25 @@ ir_minmax_visitor::opt_undefined_behaviour(ir_expression *expr, minmax_range bas
}
/**
+ * Removes useless abs.
+ *
+ * @param baserange the range of this expression that will be used by its
+ * parents, if this is applicable
+ */
+ir_rvalue *
+ir_minmax_visitor::opt_abs(ir_expression *expr, minmax_range baserange)
+{
+ // Get the range for the operand
+ minmax_range r0 = get_range(expr->operands[0]);
+
+ // Operand >= 0.0 lets us eliminate the abs
+ if (IS_CONSTANT(r0.low, >=, 0.0f))
+ return expr->operands[0];
+
+ return expr;
+}
+
+/**
* Eliminates saturate-operations that are defined to either
* 0 or 1 based on the operand being less than zero, or larger than 1.
*
@@ -863,6 +884,9 @@ ir_minmax_visitor::handle_rvalue(ir_rvalue **rvalue)
if (expr->operation == ir_unop_saturate)
new_rvalue = opt_saturate(expr, minmax_range());
+ if (expr->operation == ir_unop_abs)
+ new_rvalue = opt_abs(expr, minmax_range());
+
if (expr->operation == ir_binop_equal ||
expr->operation == ir_binop_lequal ||
expr->operation == ir_binop_gequal ||
--
2.2.1
More information about the mesa-dev
mailing list