[Mesa-dev] [PATCH 10/22] glsl: Add ir_binop_add to get_range

Thomas Helland thomashelland90 at gmail.com
Sat Jan 3 11:18:15 PST 2015


V2: Fix whitespace issues
    Put in alphabetic order
    Split resolve of add into a separate function for reuse later

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/opt_minmax.cpp | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/glsl/opt_minmax.cpp b/src/glsl/opt_minmax.cpp
index 43d6061..4153a48 100644
--- a/src/glsl/opt_minmax.cpp
+++ b/src/glsl/opt_minmax.cpp
@@ -282,6 +282,24 @@ range_intersection(minmax_range r0, minmax_range r1)
    return ret;
 }
 
+/* Takes the range of the operands in an add-operation as parameters
+ * and uses this to solve the range of the add-operation itself.
+ */
+static minmax_range
+resolv_add_range(minmax_range r0, minmax_range r1)
+{
+   ir_constant *low = NULL;
+   ir_constant *high = NULL;
+
+   if (r0.low && r1.low)
+      low = add(r0.low, r1.low)->constant_expression_value();
+
+   if (r0.high && r1.high)
+      high = add(r0.high, r1.high)->constant_expression_value();
+
+   return minmax_range(low, high);
+}
+
 static minmax_range
 get_range(ir_rvalue *rval)
 {
@@ -360,6 +378,11 @@ get_range(ir_rvalue *rval)
          return minmax_range(new(mem_ctx) ir_constant(-1.0f),
                              new(mem_ctx) ir_constant(1.0f));
 
+      case ir_binop_add:
+         r0 = get_range(expr->operands[0]);
+         r1 = get_range(expr->operands[1]);
+         return resolv_add_range(r0, r1);
+
       case ir_binop_min:
       case ir_binop_max:
          r0 = get_range(expr->operands[0]);
-- 
2.2.1



More information about the mesa-dev mailing list