From 6ec5b27f8194c93d701ca101c5bf132be55fe60d Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 13 Dec 2016 18:25:20 -0700 Subject: [PATCH] JIT: simplify output for `begin0` that's just for its non-tail effect Don't store away and restore multiple results if it's obvious that nothing happens in between. --- racket/src/racket/src/jit.c | 43 +++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/racket/src/racket/src/jit.c b/racket/src/racket/src/jit.c index ef8ff5ff55..1b5f7148f4 100644 --- a/racket/src/racket/src/jit.c +++ b/racket/src/racket/src/jit.c @@ -2253,7 +2253,7 @@ int scheme_generate(Scheme_Object *obj, mz_jit_state *jitter, int is_tail, int w { Scheme_Sequence *seq; GC_CAN_IGNORE jit_insn *ref, *ref2; - int i; + int i, count; START_JIT_DATA(); LOG_IT(("begin0\n")); @@ -2264,8 +2264,13 @@ int scheme_generate(Scheme_Object *obj, mz_jit_state *jitter, int is_tail, int w scheme_generate_non_tail(seq->array[0], jitter, multi_ok, 1, result_ignored); CHECK_LIMIT(); + count = seq->count; + /* Ignore an obviously useless expression: */ + if ((count == 2) && (SCHEME_TYPE(seq->array[1]) > _scheme_values_types_)) + count = 1; + /* Save value(s) */ - if (!result_ignored) { + if (!result_ignored && (count > 1)) { mz_pushr_p(JIT_R0); if (multi_ok) { mz_pushr_p(JIT_R0); @@ -2310,23 +2315,25 @@ int scheme_generate(Scheme_Object *obj, mz_jit_state *jitter, int is_tail, int w /* Restore values, if necessary */ if (!result_ignored) { - mz_popr_p(JIT_R0); - if (multi_ok) { - mz_popr_p(JIT_R1); - mz_popr_p(JIT_R2); - mz_rs_sync(); - CHECK_LIMIT(); - __START_TINY_JUMPS__(1); - ref = jit_bnei_p(jit_forward(), JIT_R0, 0x0); - CHECK_LIMIT(); - mz_tl_ldi_p(JIT_R0, tl_scheme_current_thread); - jit_stxi_p(&((Scheme_Thread *)0x0)->ku.multiple.array, JIT_R0, JIT_R1); - jit_rshi_ul(JIT_R2, JIT_R2, 0x1); - jit_stxi_l(&((Scheme_Thread *)0x0)->ku.multiple.count, JIT_R0, JIT_R2); - (void)jit_movi_p(JIT_R0, SCHEME_MULTIPLE_VALUES); + if (count > 1) { + mz_popr_p(JIT_R0); + if (multi_ok) { + mz_popr_p(JIT_R1); + mz_popr_p(JIT_R2); + mz_rs_sync(); + CHECK_LIMIT(); + __START_TINY_JUMPS__(1); + ref = jit_bnei_p(jit_forward(), JIT_R0, 0x0); + CHECK_LIMIT(); + mz_tl_ldi_p(JIT_R0, tl_scheme_current_thread); + jit_stxi_p(&((Scheme_Thread *)0x0)->ku.multiple.array, JIT_R0, JIT_R1); + jit_rshi_ul(JIT_R2, JIT_R2, 0x1); + jit_stxi_l(&((Scheme_Thread *)0x0)->ku.multiple.count, JIT_R0, JIT_R2); + (void)jit_movi_p(JIT_R0, SCHEME_MULTIPLE_VALUES); - mz_patch_branch(ref); - __END_TINY_JUMPS__(1); + mz_patch_branch(ref); + __END_TINY_JUMPS__(1); + } } if (target != JIT_R0)