/* make a-(-b) => a + b */
if (unary->m_op == VINSTR_NEG_F || unary->m_op == VINSTR_NEG_V) {
if (op == INSTR_SUB_F) {
- op = INSTR_ADD_F;
+ op = m_op = INSTR_ADD_F;
right = normal;
++opts_optimizationcount[OPTIM_PEEPHOLE];
} else if (op == INSTR_SUB_V) {
- op = INSTR_ADD_V;
+ op = m_op = INSTR_ADD_V;
right = normal;
++opts_optimizationcount[OPTIM_PEEPHOLE];
}
ir_block *ontrue_endblock = nullptr;
ir_block *onfalse_endblock = nullptr;
ir_block *merge = nullptr;
- int folded = 0;
/* We don't output any value, thus also don't care about r/lvalue */
(void)out;
}
m_outr = (ir_value*)1;
+ /* try constant folding away the condition */
+ switch (fold::cond_ifthen((ast_value*)m_cond, this)) {
+ case 0:
+ return true;
+ case fold::ON_TRUE:
+ return m_on_true->codegen(func, false, out);
+ case fold::ON_FALSE:
+ return m_on_false->codegen(func, false, out);
+ }
+
/* generate the condition */
if (!m_cond->codegen(func, false, &condval))
return false;
/* update the block which will get the jump - because short-logic or ternaries may have changed this */
cond = func->m_curblock;
- /* try constant folding away the condition */
- if ((folded = fold::cond_ifthen(condval, func, this)) != -1)
- return folded;
-
if (m_on_true) {
/* create on-true block */
ontrue = ir_function_create_block(m_context, func->m_ir_func, func->makeLabel("ontrue"));
ir_block *ontrue, *ontrue_out = nullptr;
ir_block *onfalse, *onfalse_out = nullptr;
ir_block *merge;
- int folded = 0;
/* Ternary can never create an lvalue... */
if (lvalue)
return true;
}
+ /* try constant folding away the condition */
+ switch (fold::cond_ternary((ast_value*)m_cond, this)) {
+ case 0:
+ return true;
+ case fold::ON_TRUE:
+ return m_on_true->codegen(func, false, out);
+ case fold::ON_FALSE:
+ return m_on_false->codegen(func, false, out);
+ }
+
/* In the following, contraty to ast_ifthen, we assume both paths exist. */
/* generate the condition */
return false;
cond_out = func->m_curblock;
- /* try constant folding away the condition */
- if ((folded = fold::cond_ternary(condval, func, this)) != -1)
- return folded;
-
/* create on-true block */
ontrue = ir_function_create_block(m_context, func->m_ir_func, func->makeLabel("tern_T"));
if (!ontrue)