From: Jan Hubicka Date: Thu, 16 Nov 2017 11:03:23 +0000 (+0100) Subject: * final.c (compute_alignments): Use counts rather than frequencies. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6786ba1aaa8533e286b8d8f333cc9d75cf5c9989;p=gcc.git * final.c (compute_alignments): Use counts rather than frequencies. From-SVN: r254809 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e3bf8eed1f1..93d4cb3423c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2017-11-14 Jan Hubicka + + * final.c (compute_alignments): Use counts rather than frequencies. + 2017-11-14 Jan Hubicka * cfgloopanal.c: Include sreal.h diff --git a/gcc/final.c b/gcc/final.c index fe35a36dbbf..672c5bbc49c 100644 --- a/gcc/final.c +++ b/gcc/final.c @@ -661,16 +661,13 @@ insn_current_reference_address (rtx_insn *branch) } } -/* Compute branch alignments based on frequency information in the - CFG. */ +/* Compute branch alignments based on CFG profile. */ unsigned int compute_alignments (void) { int log, max_skip, max_log; basic_block bb; - int freq_max = 0; - int freq_threshold = 0; if (label_align) { @@ -693,17 +690,19 @@ compute_alignments (void) flow_loops_dump (dump_file, NULL, 1); } loop_optimizer_init (AVOID_CFG_MODIFICATIONS); - FOR_EACH_BB_FN (bb, cfun) - if (bb->count.to_frequency (cfun) > freq_max) - freq_max = bb->count.to_frequency (cfun); - freq_threshold = freq_max / PARAM_VALUE (PARAM_ALIGN_THRESHOLD); + profile_count count_threshold = cfun->cfg->count_max.apply_scale + (1, PARAM_VALUE (PARAM_ALIGN_THRESHOLD)); if (dump_file) - fprintf (dump_file, "freq_max: %i\n",freq_max); + { + fprintf (dump_file, "count_max: "); + cfun->cfg->count_max.dump (dump_file); + fprintf (dump_file, "\n"); + } FOR_EACH_BB_FN (bb, cfun) { rtx_insn *label = BB_HEAD (bb); - int fallthru_frequency = 0, branch_frequency = 0, has_fallthru = 0; + bool has_fallthru = 0; edge e; edge_iterator ei; @@ -712,35 +711,41 @@ compute_alignments (void) { if (dump_file) fprintf (dump_file, - "BB %4i freq %4i loop %2i loop_depth %2i skipped.\n", - bb->index, bb->count.to_frequency (cfun), + "BB %4i loop %2i loop_depth %2i skipped.\n", + bb->index, bb->loop_father->num, bb_loop_depth (bb)); continue; } max_log = LABEL_ALIGN (label); max_skip = targetm.asm_out.label_align_max_skip (label); + profile_count fallthru_count = profile_count::zero (); + profile_count branch_count = profile_count::zero (); FOR_EACH_EDGE (e, ei, bb->preds) { if (e->flags & EDGE_FALLTHRU) - has_fallthru = 1, fallthru_frequency += EDGE_FREQUENCY (e); + has_fallthru = 1, fallthru_count += e->count (); else - branch_frequency += EDGE_FREQUENCY (e); + branch_count += e->count (); } if (dump_file) { - fprintf (dump_file, "BB %4i freq %4i loop %2i loop_depth" - " %2i fall %4i branch %4i", - bb->index, bb->count.to_frequency (cfun), bb->loop_father->num, - bb_loop_depth (bb), - fallthru_frequency, branch_frequency); + fprintf (dump_file, "BB %4i loop %2i loop_depth" + " %2i fall ", + bb->index, bb->loop_father->num, + bb_loop_depth (bb)); + fallthru_count.dump (dump_file); + fprintf (dump_file, " branch "); + branch_count.dump (dump_file); if (!bb->loop_father->inner && bb->loop_father->num) fprintf (dump_file, " inner_loop"); if (bb->loop_father->header == bb) fprintf (dump_file, " loop_header"); fprintf (dump_file, "\n"); } + if (!fallthru_count.initialized_p () || !branch_count.initialized_p ()) + continue; /* There are two purposes to align block with no fallthru incoming edge: 1) to avoid fetch stalls when branch destination is near cache boundary @@ -753,11 +758,11 @@ compute_alignments (void) when function is called. */ if (!has_fallthru - && (branch_frequency > freq_threshold - || (bb->count.to_frequency (cfun) - > bb->prev_bb->count.to_frequency (cfun) * 10 - && (bb->prev_bb->count.to_frequency (cfun) - <= ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun) / 2)))) + && (branch_count > count_threshold + || (bb->count > bb->prev_bb->count.apply_scale (10, 1) + && (bb->prev_bb->count + <= ENTRY_BLOCK_PTR_FOR_FN (cfun) + ->count.apply_scale (1, 2))))) { log = JUMP_ALIGN (label); if (dump_file) @@ -774,9 +779,10 @@ compute_alignments (void) && !(single_succ_p (bb) && single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun)) && optimize_bb_for_speed_p (bb) - && branch_frequency + fallthru_frequency > freq_threshold - && (branch_frequency - > fallthru_frequency * PARAM_VALUE (PARAM_ALIGN_LOOP_ITERATIONS))) + && branch_count + fallthru_count > count_threshold + && (branch_count + > fallthru_count.apply_scale + (PARAM_VALUE (PARAM_ALIGN_LOOP_ITERATIONS), 1))) { log = LOOP_ALIGN (label); if (dump_file)