dead code elimination for constant-valued if/then/else
authorBrian <brian@yutani.localnet.net>
Mon, 26 Mar 2007 21:02:21 +0000 (15:02 -0600)
committerBrian <brian@yutani.localnet.net>
Mon, 26 Mar 2007 21:02:21 +0000 (15:02 -0600)
src/mesa/shader/slang/slang_codegen.c

index 4a67d4535aade156d1b1993934de0b376f455eb1..f9dae9f7aa1686079141eb2e055dab6a5c36a5af 100644 (file)
@@ -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);