summaryrefslogtreecommitdiffstats
path: root/src/mesa/shader/slang/slang_codegen.c
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-03-26 15:02:21 -0600
committerBrian <[email protected]>2007-03-26 15:02:21 -0600
commite508155d1658571244aeb981dd42e452417d4af4 (patch)
treea75c4a1278f44e6afd553847f43ea92de1d3edcb /src/mesa/shader/slang/slang_codegen.c
parent0426d3c0c85b652c2c4e8509f709863e08644295 (diff)
dead code elimination for constant-valued if/then/else
Diffstat (limited to 'src/mesa/shader/slang/slang_codegen.c')
-rw-r--r--src/mesa/shader/slang/slang_codegen.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index 4a67d4535aa..f9dae9f7aa1 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -1482,6 +1482,19 @@ _slang_gen_if(slang_assemble_ctx * A, const slang_operation *oper)
*/
const GLboolean haveElseClause = !_slang_is_noop(&oper->children[2]);
slang_ir_node *ifNode, *cond, *ifBody, *elseBody;
+ GLboolean isConst, constTrue;
+
+ isConst = _slang_is_constant_cond(&oper->children[0], &constTrue);
+ if (isConst) {
+ if (constTrue) {
+ /* if (true) ... */
+ return _slang_gen_operation(A, &oper->children[1]);
+ }
+ else {
+ /* if (false) ... */
+ return _slang_gen_operation(A, &oper->children[2]);
+ }
+ }
cond = _slang_gen_operation(A, &oper->children[0]);
cond = new_cond(cond);