From: Dale Weiler Date: Wed, 28 Aug 2013 14:39:48 +0000 (-0400) Subject: Fix fold-dce for if(0) X-Git-Tag: 0.3.5~125 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ee428b9081c5f64707a5c7e20234c8019fe49d0b;p=xonotic%2Fgmqcc.git Fix fold-dce for if(0) --- diff --git a/fold.c b/fold.c index 4019794..02335f2 100644 --- a/fold.c +++ b/fold.c @@ -707,8 +707,15 @@ int fold_cond(ir_value *condval, ast_function *func, ast_ifthen *branch) { bool isfalse = (fold_immvalue_float(condval) == 0.0f && branch->on_false); ast_expression *path = (istrue) ? branch->on_true : (isfalse) ? branch->on_false : NULL; - if (!path) - return false; + if (!path) { + /* + * no path to take implies that the evaluation is if(0) and there + * is no else block. so eliminate all the code. + */ + ++opts_optimizationcount[OPTIM_CONST_FOLD_DCE]; + return true; + } + if (!(elide = ir_function_create_block(ast_ctx(branch), func->ir_func, ast_function_label(func, ((istrue) ? "ontrue" : "onfalse"))))) return false; if (!(*(cgen = path->codegen))((ast_expression*)path, func, false, &dummy))