From 14f8e16132409f38656e4874aa53bc471977f9ad Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 20 Jul 2010 11:43:28 -0700 Subject: [PATCH] glsl2: Constant-fold assignment conditions. --- src/glsl/ir_constant_folding.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/glsl/ir_constant_folding.cpp b/src/glsl/ir_constant_folding.cpp index 2daa6fde38d..66a92e9f3b6 100644 --- a/src/glsl/ir_constant_folding.cpp +++ b/src/glsl/ir_constant_folding.cpp @@ -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(); + } + } } -- 2.30.2