diff options
author | rsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-05-04 11:37:05 +0000 |
---|---|---|
committer | rsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-05-04 11:37:05 +0000 |
commit | 10de1374e1bd9a06ff0dd2a54a9732a7096eeacb (patch) | |
tree | 9e4572707089e2b42a80ecb24d4d3b00ae89d8a3 | |
parent | 2a9d6f178af732cd54a5fec05e3f9cb6664edc3a (diff) | |
download | gcc-10de1374e1bd9a06ff0dd2a54a9732a7096eeacb.tar.gz |
Cap niter_for_unrolled_loop to upper bound
For the reasons explained in PR77536, niter_for_unrolled_loop assumes 5
iterations in the absence of profiling information, although it doesn't
increase beyond the estimate for the original loop. This left a hole in
which the new estimate could be less than the old one but still greater
than the limit imposed by CEIL (nb_iterations_upper_bound, unroll factor).
2017-05-04 Richard Sandiford <richard.sandiford@linaro.org>
gcc/
* tree-ssa-loop-manip.c (niter_for_unrolled_loop): Add commentary
to explain the use of truncating division. Cap the number of
iterations to the maximum given by nb_iterations_upper_bound,
if defined.
gcc/testsuite/
* gcc.dg/vect/vect-profile-1.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@247591 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/vect-profile-1.c | 35 | ||||
-rw-r--r-- | gcc/tree-ssa-loop-manip.c | 12 |
4 files changed, 58 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9791c007345..85488453796 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-05-04 Richard Sandiford <richard.sandiford@linaro.org> + + * tree-ssa-loop-manip.c (niter_for_unrolled_loop): Add commentary + to explain the use of truncating division. Cap the number of + iterations to the maximum given by nb_iterations_upper_bound, + if defined. + 2017-05-04 Thomas Preud'homme <thomas.preudhomme@arm.com> * configure.ac (--enable-mingw-wildcard): Add new configurable feature. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b93975d07a4..39fc9284da3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-05-04 Richard Sandiford <richard.sandiford@linaro.org> + + * gcc.dg/vect/vect-profile-1.c: New test. + 2017-05-04 Marek Polacek <polacek@redhat.com> PR tree-optimization/80612 diff --git a/gcc/testsuite/gcc.dg/vect/vect-profile-1.c b/gcc/testsuite/gcc.dg/vect/vect-profile-1.c new file mode 100644 index 00000000000..93d7ad13147 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-profile-1.c @@ -0,0 +1,35 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-additional-options "-fdump-tree-vect-details-blocks" } */ + +/* At least one of these should correspond to a full vector. */ + +void +f1 (int *x) +{ + for (int j = 0; j < 2; ++j) + x[j] += 1; +} + +void +f2 (int *x) +{ + for (int j = 0; j < 4; ++j) + x[j] += 1; +} + +void +f3 (int *x) +{ + for (int j = 0; j < 8; ++j) + x[j] += 1; +} + +void +f4 (int *x) +{ + for (int j = 0; j < 16; ++j) + x[j] += 1; +} + +/* { dg-final { scan-tree-dump {goto <bb [0-9]+>; \[0+.0*%\]} vect } } */ diff --git a/gcc/tree-ssa-loop-manip.c b/gcc/tree-ssa-loop-manip.c index 70d1f8444a4..d3a57f124fb 100644 --- a/gcc/tree-ssa-loop-manip.c +++ b/gcc/tree-ssa-loop-manip.c @@ -1104,6 +1104,9 @@ niter_for_unrolled_loop (struct loop *loop, unsigned factor) gcc_assert (factor != 0); bool profile_p = false; gcov_type est_niter = expected_loop_iterations_unbounded (loop, &profile_p); + /* Note that this is really CEIL (est_niter + 1, factor) - 1, where the + "+ 1" converts latch iterations to loop iterations and the "- 1" + converts back. */ gcov_type new_est_niter = est_niter / factor; /* Without profile feedback, loops for which we do not know a better estimate @@ -1120,6 +1123,15 @@ niter_for_unrolled_loop (struct loop *loop, unsigned factor) new_est_niter = 5; } + if (loop->any_upper_bound) + { + /* As above, this is really CEIL (upper_bound + 1, factor) - 1. */ + widest_int bound = wi::udiv_floor (loop->nb_iterations_upper_bound, + factor); + if (wi::ltu_p (bound, new_est_niter)) + new_est_niter = bound.to_uhwi (); + } + return new_est_niter; } |