/* update the block which will get the jump - because short-logic or ternaries may have changed this */
cond = func->curblock;
- /* try constant folding away the if */
- if ((fold = fold_cond(condval, func, self)) != -1)
+ /* try constant folding away the condition */
+ if ((fold = fold_cond_ifthen(condval, func, self)) != -1)
return fold;
if (self->on_true) {
ir_block *ontrue, *ontrue_out = NULL;
ir_block *onfalse, *onfalse_out = NULL;
ir_block *merge;
+ int fold = 0;
/* Ternary can never create an lvalue... */
if (lvalue)
return false;
cond_out = func->curblock;
+ /* try constant folding away the condition */
+ if ((fold = fold_cond_ternary(condval, func, self)) != -1)
+ return fold;
+
/* create on-true block */
ontrue = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "tern_T"));
if (!ontrue)
/*#define fold_can_2(X,Y) (fold_can_1(X) && fold_can_1(Y))*/
-int fold_cond(ir_value *condval, ast_function *func, ast_ifthen *branch) {
+static GMQCC_INLINE int fold_cond(ir_value *condval, ast_function *func, ast_ifthen *branch) {
if (isfloat(condval) && fold_can_1(condval) && OPTS_OPTIMIZATION(OPTIM_CONST_FOLD_DCE)) {
ast_expression_codegen *cgen;
ir_block *elide;
}
return -1; /* nothing done */
}
+
+int fold_cond_ternary(ir_value *condval, ast_function *func, ast_ternary *branch) {
+ return fold_cond(condval, func, (ast_ifthen*)branch);
+}
+
+int fold_cond_ifthen(ir_value *condval, ast_function *func, ast_ifthen *branch) {
+ return fold_cond(condval, func, branch);
+}
ast_expression *fold_op (fold_t *, const oper_info *, ast_expression **);
ast_expression *fold_intrin (fold_t *, const char *, ast_expression **);
-int fold_cond (ir_value *, ast_function *, ast_ifthen *);
+int fold_cond_ifthen (ir_value *, ast_function *, ast_ifthen *);
+int fold_cond_ternary (ir_value *, ast_function *, ast_ternary *);
/* intrin.c */
intrin_t *intrin_init (parser_t *parser);