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 b9dee37edfb71fd8ae4bc0d792ab008258667570..006eb5ffcfcec733c25f64f28ec6c06cef2f2d37 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);
 }