glsl: Generate code for constant ir_binop_ldexp expressions
[mesa.git] / src / compiler / glsl / opt_constant_propagation.cpp
index 4764d16de6d3f8bc44c6d7abec2224c129c9c7b3..69bca744ee7a4067e888cd150acf84875ed19455 100644 (file)
@@ -136,32 +136,21 @@ public:
 
 
 void
-ir_constant_propagation_visitor::constant_folding(ir_rvalue **rvalue) {
-
-   if (*rvalue == NULL || (*rvalue)->ir_type == ir_type_constant)
-      return;
-
-   /* Note that we visit rvalues one leaving.  So if an expression has a
-    * non-constant operand, no need to go looking down it to find if it's
-    * constant.  This cuts the time of this pass down drastically.
-    */
-   ir_expression *expr = (*rvalue)->as_expression();
-   if (expr) {
-      for (unsigned int i = 0; i < expr->get_num_operands(); i++) {
-        if (!expr->operands[i]->as_constant())
-           return;
-      }
-   }
-
-   /* Ditto for swizzles. */
-   ir_swizzle *swiz = (*rvalue)->as_swizzle();
-   if (swiz && !swiz->val->as_constant())
+ir_constant_propagation_visitor::constant_folding(ir_rvalue **rvalue)
+{
+   if (this->in_assignee || *rvalue == NULL)
       return;
 
-   ir_constant *constant = (*rvalue)->constant_expression_value();
-   if (constant) {
-      *rvalue = constant;
+   if (ir_constant_fold(rvalue))
       this->progress = true;
+
+   ir_dereference_variable *var_ref = (*rvalue)->as_dereference_variable();
+   if (var_ref && !var_ref->type->is_array()) {
+      ir_constant *constant = var_ref->constant_expression_value();
+      if (constant) {
+         *rvalue = constant;
+         this->progress = true;
+      }
    }
 }