diff options
author | Eric Anholt <[email protected]> | 2010-08-26 10:42:47 -0700 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2010-08-26 10:53:20 -0700 |
commit | 2db7bb9c665d13fd067109b1171eedd92764791d (patch) | |
tree | d9e553a7d4e5ffa1293b7040f44c7bdc125d1a5c /src/glsl | |
parent | 9b4384c32233c6d75021bcc67552b7ea9dc56de6 (diff) |
glsl: Add a quick hack to constant folding to reduce duplicated work.
Reduces runtime of glsl-max-varyings 92% on my system.
Diffstat (limited to 'src/glsl')
-rw-r--r-- | src/glsl/ir_constant_folding.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/glsl/ir_constant_folding.cpp b/src/glsl/ir_constant_folding.cpp index 3e6934c9a7c..554c54fae3a 100644 --- a/src/glsl/ir_constant_folding.cpp +++ b/src/glsl/ir_constant_folding.cpp @@ -62,6 +62,19 @@ ir_constant_folding_visitor::handle_rvalue(ir_rvalue **rvalue) if (*rvalue == NULL || (*rvalue)->ir_type == ir_type_constant) return; + /* Note that we do rvalue visitoring on 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; + } + } + ir_constant *constant = (*rvalue)->constant_expression_value(); if (constant) { *rvalue = constant; |