From 65739a688542b637b6a9f99aed2de84d9b84460c Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Fri, 13 Apr 2018 10:59:05 +0200 Subject: re PR tree-optimization/82965 (gcc.dg/vect/pr79347.c starts failing after r254379) PR tree-optimization/82965 PR tree-optimization/83991 * cfgloopanal.c (expected_loop_iterations_unbounded): Add by_profile_only parameter. * cfgloopmanip.c (scale_loop_profile): Further scale loop's profile information if the loop was predicted to iterate too many times. * cfgloop.h (expected_loop_iterations_unbounded): Update prototype Co-Authored-By: Bin Cheng From-SVN: r259368 --- gcc/cfgloopanal.c | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'gcc/cfgloopanal.c') diff --git a/gcc/cfgloopanal.c b/gcc/cfgloopanal.c index 9151a33..3af0b2d 100644 --- a/gcc/cfgloopanal.c +++ b/gcc/cfgloopanal.c @@ -230,12 +230,17 @@ average_num_loop_insns (const struct loop *loop) } /* Returns expected number of iterations of LOOP, according to - measured or guessed profile. No bounding is done on the - value. */ + measured or guessed profile. + + This functions attempts to return "sane" value even if profile + information is not good enough to derive osmething. + If BY_PROFILE_ONLY is set, this logic is bypassed and function + return -1 in those scenarios. */ gcov_type expected_loop_iterations_unbounded (const struct loop *loop, - bool *read_profile_p) + bool *read_profile_p, + bool by_profile_only) { edge e; edge_iterator ei; @@ -246,7 +251,11 @@ expected_loop_iterations_unbounded (const struct loop *loop, /* If we have no profile at all, use AVG_LOOP_NITER. */ if (profile_status_for_fn (cfun) == PROFILE_ABSENT) - expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER); + { + if (by_profile_only) + return -1; + expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER); + } else if (loop->latch && (loop->latch->count.initialized_p () || loop->header->count.initialized_p ())) { @@ -260,9 +269,17 @@ expected_loop_iterations_unbounded (const struct loop *loop, count_in += e->count (); if (!count_latch.initialized_p ()) - expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER); + { + if (by_profile_only) + return -1; + expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER); + } else if (!count_in.nonzero_p ()) - expected = count_latch.to_gcov_type () * 2; + { + if (by_profile_only) + return -1; + expected = count_latch.to_gcov_type () * 2; + } else { expected = (count_latch.to_gcov_type () + count_in.to_gcov_type () @@ -273,11 +290,18 @@ expected_loop_iterations_unbounded (const struct loop *loop, } } else - expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER); + { + if (by_profile_only) + return -1; + expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER); + } - HOST_WIDE_INT max = get_max_loop_iterations_int (loop); - if (max != -1 && max < expected) - return max; + if (!by_profile_only) + { + HOST_WIDE_INT max = get_max_loop_iterations_int (loop); + if (max != -1 && max < expected) + return max; + } return expected; } -- cgit v1.1