diff options
author | Jan Hubicka <hubicka@ucw.cz> | 2016-06-10 14:46:30 +0200 |
---|---|---|
committer | Jan Hubicka <hubicka@gcc.gnu.org> | 2016-06-10 12:46:30 +0000 |
commit | aade5c72c6adb395d2bddb0d08c6626d537a1714 (patch) | |
tree | 51e6e0da3d401e02cfe021ad40bcd7b0cf5e8df6 | |
parent | 1f24fd3e734381f5e268d3a9897a2268b6d0485b (diff) | |
download | gcc-aade5c72c6adb395d2bddb0d08c6626d537a1714.zip gcc-aade5c72c6adb395d2bddb0d08c6626d537a1714.tar.gz gcc-aade5c72c6adb395d2bddb0d08c6626d537a1714.tar.bz2 |
profile.c: Include cfgloop.h.
* profile.c: Include cfgloop.h.
(branch_prob): Compute estimated number of iterations.
* tree-ssa-loop-niter.c (estimate_numbers_of_iterations_loop): Do not
recompute estimate number of iterations from profile.
From-SVN: r237305
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/profile.c | 13 | ||||
-rw-r--r-- | gcc/tree-ssa-loop-niter.c | 33 |
3 files changed, 40 insertions, 13 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d9852c5..954adf3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-06-10 Jan Hubicka <hubicka@ucw.cz> + + * profile.c: Include cfgloop.h. + (branch_prob): Compute estimated number of iterations. + * tree-ssa-loop-niter.c (estimate_numbers_of_iterations_loop): Do not + recompute estimate number of iterations from profile. + 2016-06-10 Bernd Edlinger <bernd.edlinger@hotmail.de> PR inline-asm/68843 diff --git a/gcc/profile.c b/gcc/profile.c index 9925bb5..4519e7d 100644 --- a/gcc/profile.c +++ b/gcc/profile.c @@ -63,6 +63,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-iterator.h" #include "tree-cfg.h" #include "dumpfile.h" +#include "cfgloop.h" #include "profile.h" @@ -1329,9 +1330,21 @@ branch_prob (void) coverage_end_function (lineno_checksum, cfg_checksum); if (flag_branch_probabilities && profile_info) { + struct loop *loop; if (dump_file && (dump_flags & TDF_DETAILS)) report_predictor_hitrates (); profile_status_for_fn (cfun) = PROFILE_READ; + + /* At this moment we have precise loop iteration count estimates. + Record them to loop structure before the profile gets out of date. */ + FOR_EACH_LOOP (loop, 0) + if (loop->header->count) + { + gcov_type nit = expected_loop_iterations_unbounded (loop); + widest_int bound = gcov_type_to_wide_int (nit); + loop->any_estimate = false; + record_niter_bound (loop, bound, true, false); + } compute_function_frequency (); } } diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index 7804036..32fe2f9 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -3721,8 +3721,26 @@ estimate_numbers_of_iterations_loop (struct loop *loop) return; loop->estimate_state = EST_AVAILABLE; - /* Force estimate compuation but leave any existing upper bound in place. */ - loop->any_estimate = false; + + /* If we have a measured profile, use it to estimate the number of + iterations. Normally this is recorded by branch_prob right after + reading the profile. In case we however found a new loop, record the + information here. + + Explicitly check for profile status so we do not report + wrong prediction hitrates for guessed loop iterations heuristics. + Do not recompute already recorded bounds - we ought to be better on + updating iteration bounds than updating profile in general and thus + recomputing iteration bounds later in the compilation process will just + introduce random roundoff errors. */ + if (!loop->any_estimate + && loop->header->count != 0 + && profile_status_for_fn (cfun) >= PROFILE_READ) + { + gcov_type nit = expected_loop_iterations_unbounded (loop); + bound = gcov_type_to_wide_int (nit); + record_niter_bound (loop, bound, true, false); + } /* Ensure that loop->nb_iterations is computed if possible. If it turns out to be constant, we avoid undefined behavior implied bounds and instead @@ -3756,17 +3774,6 @@ estimate_numbers_of_iterations_loop (struct loop *loop) maybe_lower_iteration_bound (loop); - /* If we have a measured profile, use it to estimate the number of - iterations. Explicitly check for profile status so we do not report - wrong prediction hitrates for guessed loop iterations heuristics. */ - if (loop->header->count != 0 - && profile_status_for_fn (cfun) >= PROFILE_READ) - { - gcov_type nit = expected_loop_iterations_unbounded (loop); - bound = gcov_type_to_wide_int (nit); - record_niter_bound (loop, bound, true, false); - } - /* If we know the exact number of iterations of this loop, try to not break code with undefined behavior by not recording smaller maximum number of iterations. */ |