Unexpected evaluation in conditional branch
Dibyendu Majumdar
mobile@majumdar.org.uk
Thu Jan 1 00:00:00 GMT 2015
Hi Dave,
I have scenario where the conditional branch is evaluating the result
of a comparison - one of the operands of the comparison is a function
call. The generated code appears to evaluate the comparison twice -
once for the true branch and once for the false branch - which is not
what I am expecting. I can of course store the result of the
comparison in a local variable and then perform conditional branch on
the variable but I wanted to check whether this behaviour is as
expected.
My code is this:
gcc_jit_rvalue *ra = ravi_emit_get_register(def, A);
gcc_jit_rvalue *nresults_const = gcc_jit_context_new_rvalue_from_int(
def->function_context, def->ravi->types->C_intT, nresults);
gcc_jit_rvalue *precall_result = ravi_function_call3_rvalue(
def, def->ravi->types->luaD_precallT, gcc_jit_param_as_rvalue(def->L), ra,
nresults_const);
gcc_jit_rvalue *zero_const = gcc_jit_context_new_rvalue_from_int(
def->function_context, def->ravi->types->C_intT, 0);
gcc_jit_rvalue *precall_bool = gcc_jit_context_new_comparison(
def->function_context, NULL, GCC_JIT_COMPARISON_EQ, precall_result,
zero_const);
gcc_jit_block *then_block = gcc_jit_function_new_block(
def->jit_function, unique_name(def, "OP_CALL_if_lua_function", pc));
gcc_jit_block *else_block = gcc_jit_function_new_block(
def->jit_function, unique_name(def, "OP_CALL_else_lua_function", pc));
gcc_jit_block *end_block = gcc_jit_function_new_block(
def->jit_function, unique_name(def, "OP_CALL_done", pc));
ravi_emit_conditional_branch(def, precall_bool, then_block, else_block);
The output I get is this:
base = L->ci->u.l.base;
&base[(int)1]->value_.b = (int)1;
&base[(int)1]->tt_ = (int)1;
base = L->ci->u.l.base;
L->top = &base[(int)2];
if (luaD_precall (L, &base[(int)0], (int)0) == (int)0) goto
OP_CALL_if_lua_function_2_1; else goto OP_CALL_else_lua_function_2_2;
OP_CALL_if_lua_function_2_1:
(void)luaV_execute (L);
goto OP_CALL_done_2_3;
OP_CALL_else_lua_function_2_2:
if (luaD_precall (L, &base[(int)0], (int)0) == (int)1) goto
OP_CALL_if_C_function_2_4; else goto OP_CALL_done_2_3;
Regards
Dibyendu
More information about the Jit
mailing list