Perform constant folding on array indices.
authorEric Anholt <eric@anholt.net>
Tue, 6 Apr 2010 18:11:05 +0000 (11:11 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 6 Apr 2010 18:42:34 +0000 (11:42 -0700)
Replaces a constant var deref with a constant value in CorrectParse1.frag.

ir_constant_folding.cpp

index b9dee37..006eb5f 100644 (file)
@@ -88,7 +88,14 @@ ir_constant_folding_visitor::visit(ir_swizzle *ir)
 void
 ir_constant_folding_visitor::visit(ir_dereference *ir)
 {
-   (void) ir;
+   if (ir->mode == ir_dereference::ir_reference_array) {
+      ir_constant *const_val = ir->selector.array_index->constant_expression_value();
+      if (const_val)
+        ir->selector.array_index = const_val;
+      else
+        ir->selector.array_index->accept(this);
+   }
+   ir->var->accept(this);
 }