glsl2: Constant-fold assignment conditions.
authorEric Anholt <eric@anholt.net>
Tue, 20 Jul 2010 18:43:28 +0000 (11:43 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 20 Jul 2010 19:01:40 +0000 (12:01 -0700)
src/glsl/ir_constant_folding.cpp

index 2daa6fde38de91de34be6b72d19d037197da1e36..66a92e9f3b632b72f5953c60ae936ff9b5234d46 100644 (file)
@@ -167,6 +167,19 @@ ir_constant_folding_visitor::visit(ir_assignment *ir)
       ir->rhs = const_val;
    else
       ir->rhs->accept(this);
+
+   if (ir->condition) {
+      /* If the condition is constant, either remove the condition or
+       * remove the never-executed assignment.
+       */
+      const_val = ir->condition->constant_expression_value();
+      if (const_val) {
+        if (const_val->value.b[0])
+           ir->condition = NULL;
+        else
+           ir->remove();
+      }
+   }
 }