Hi, the hack to report predictor hitrates by re-running branch prediction has a quirk because the loop niter code feeds the "loop iterations guessed" predictor by the feedback data, so it is incorrectly reported as predicting many loops.
This patch avoids that by using the data only when profile is fully read. Bootstrapped/regtested x86_64-linux, comitted. Honza * tree-ssa-loop-niter.c (estimate_numbers_of_iterations_loop): Avoid use of profile unless profile status is PROFILE_READ. * profile.c (compute_branch_probabilities): Set profile status only after reporting predictor hitrates. Index: tree-ssa-loop-niter.c =================================================================== --- tree-ssa-loop-niter.c (revision 237067) +++ tree-ssa-loop-niter.c (working copy) @@ -3757,10 +3757,12 @@ estimate_numbers_of_iterations_loop (str maybe_lower_iteration_bound (loop); /* If we have a measured profile, use it to estimate the number of - iterations. */ - if (loop->header->count != 0) + 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) + 1; + gcov_type nit = expected_loop_iterations_unbounded (loop); bound = gcov_type_to_wide_int (nit); record_niter_bound (loop, bound, true, false); } Index: profile.c =================================================================== --- profile.c (revision 237067) +++ profile.c (working copy) @@ -826,8 +826,6 @@ compute_branch_probabilities (unsigned c } } counts_to_freqs (); - profile_status_for_fn (cfun) = PROFILE_READ; - compute_function_frequency (); if (dump_file) { @@ -1329,8 +1327,13 @@ branch_prob (void) values.release (); free_edge_list (el); coverage_end_function (lineno_checksum, cfg_checksum); - if (dump_file && (dump_flags & TDF_DETAILS)) - report_predictor_hitrates (); + if (flag_branch_probabilities && profile_info) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + report_predictor_hitrates (); + profile_status_for_fn (cfun) = PROFILE_READ; + compute_function_frequency (); + } } /* Union find algorithm implementation for the basic blocks using