diff options
author | Damien George <damien@micropython.org> | 2022-06-17 23:06:24 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-06-20 22:28:18 +1000 |
commit | e85a096302e8b186b82c74e7da4e1a29ef62d9c6 (patch) | |
tree | ba0c03f2dd7b57b9d22c4cb28912e9f4585ec6ef /py/compile.c | |
parent | 0db046b67b8ed171f4898e851c3da39aab297ce9 (diff) |
py/emit: Remove logic to detect last-emit-was-return-value.
This optimisation to remove dead code is not as good as it could be.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/compile.c')
-rw-r--r-- | py/compile.c | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/py/compile.c b/py/compile.c index 9cca5df40..ff3e5ffc6 100644 --- a/py/compile.c +++ b/py/compile.c @@ -1330,12 +1330,8 @@ STATIC void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { goto done; } - if ( - // optimisation: don't jump over non-existent elif/else blocks - !(MP_PARSE_NODE_IS_NULL(pns->nodes[2]) && MP_PARSE_NODE_IS_NULL(pns->nodes[3])) - // optimisation: don't jump if last instruction was return - && !EMIT(last_emit_was_return_value) - ) { + // optimisation: don't jump over non-existent elif/else blocks + if (!(MP_PARSE_NODE_IS_NULL(pns->nodes[2]) && MP_PARSE_NODE_IS_NULL(pns->nodes[3]))) { // jump over elif/else blocks EMIT_ARG(jump, l_end); } @@ -1362,10 +1358,7 @@ STATIC void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { goto done; } - // optimisation: don't jump if last instruction was return - if (!EMIT(last_emit_was_return_value)) { - EMIT_ARG(jump, l_end); - } + EMIT_ARG(jump, l_end); EMIT_ARG(label_assign, l_fail); } } @@ -1580,9 +1573,7 @@ STATIC void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT_ARG(for_iter, pop_label); c_assign(comp, pns->nodes[0], ASSIGN_STORE); // variable compile_node(comp, pns->nodes[2]); // body - if (!EMIT(last_emit_was_return_value)) { - EMIT_ARG(jump, continue_label); - } + EMIT_ARG(jump, continue_label); EMIT_ARG(label_assign, pop_label); EMIT(for_iter_end); @@ -3048,11 +3039,8 @@ STATIC bool compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { } compile_node(comp, pns->nodes[3]); // 3 is function body - // emit return if it wasn't the last opcode - if (!EMIT(last_emit_was_return_value)) { - EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE); - EMIT(return_value); - } + EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE); + EMIT(return_value); } else if (scope->kind == SCOPE_LAMBDA) { assert(MP_PARSE_NODE_IS_STRUCT(scope->pn)); mp_parse_node_struct_t *pns = (mp_parse_node_struct_t *)scope->pn; |