Spill globals early if their next use is in call. They'll be spilled anyway in this case.
Signed-off-by: Kirill Batuzov <batuz...@ispras.ru> --- tcg/tcg.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 8ab556d..ad5bd71 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1297,6 +1297,11 @@ static void tcg_liveness_analysis(TCGContext *s) if (!(call_flags & TCG_CALL_CONST)) { /* globals are live (they may be used by the call) */ memset(dead_temps, 0, s->nb_globals); +#ifdef USE_ADVANCED_REGALLOC + for (i = 0; i < s->nb_globals; i++) { + temp_next_use[i] = op_index; + } +#endif } /* input args are live */ @@ -1393,6 +1398,11 @@ static void tcg_liveness_analysis(TCGContext *s) } else if (def->flags & TCG_OPF_CALL_CLOBBER) { /* globals are live */ memset(dead_temps, 0, s->nb_globals); +#ifdef USE_ADVANCED_REGALLOC + for (i = 0; i < s->nb_globals; i++) { + temp_next_use[i] = op_index; + } +#endif } /* input args are live */ @@ -2190,6 +2200,14 @@ static inline int tcg_gen_code_common(TCGContext *s, uint8_t *gen_code_buf, #endif dead_iargs = s->op_dead_iargs[op_index]; tcg_reg_alloc_mov(s, def, args, param_next_use_ptr, dead_iargs); +#ifdef USE_ADVANCED_REGALLOC + if (args[0] < s->nb_globals) { + if (tcg_op_defs[gen_opc_buf[param_next_use_ptr[0]]].flags + & TCG_OPF_CALL_CLOBBER) { + tcg_reg_free(s, s->temps[args[0]].reg); + } + } +#endif break; case INDEX_op_movi_i32: #if TCG_TARGET_REG_BITS == 64 -- 1.7.4.1