Fix nb_iterations_estimate calculation in tree-vect-loop.c

vect_transform_loop has to reduce three iteration counts by
the vectorisation factor: nb_iterations_upper_bound,
nb_iterations_likely_upper_bound and nb_iterations_estimate.
All three are latch execution counts rather than loop body
execution counts.  The calculations were taking that into
account for the first two, but not for nb_iterations_estimate.

This patch updates the way the calculations are done to fix
this and to add a bit more commentary about what is going on.

gcc/
2016-11-15  Richard Sandiford  <richard.sandiford@arm.com>
	    Alan Hayward  <alan.hayward@arm.com>
	    David Sherwood  <david.sherwood@arm.com>

	* tree-vect-loop.c (vect_transform_loop): Protect the updates of
	all three iteration counts with an any_* test.  Use a single update
	for each count.  Fix the calculation of nb_iterations_estimate.

Co-Authored-By: Alan Hayward <alan.hayward@arm.com>
Co-Authored-By: David Sherwood <david.sherwood@arm.com>

From-SVN: r242475
This commit is contained in:
Richard Sandiford 2016-11-16 10:18:25 +00:00 committed by Richard Sandiford
parent 3623815a51
commit 29220523c1
2 changed files with 26 additions and 20 deletions

View File

@ -1,3 +1,11 @@
2016-11-16 Richard Sandiford <richard.sandiford@arm.com>
Alan Hayward <alan.hayward@arm.com>
David Sherwood <david.sherwood@arm.com>
* tree-vect-loop.c (vect_transform_loop): Protect the updates of
all three iteration counts with an any_* test. Use a single update
for each count. Fix the calculation of nb_iterations_estimate.
2016-11-16 Richard Sandiford <richard.sandiford@arm.com>
* config/pdp11/pdp11.c: Include dbxout.h.

View File

@ -7043,27 +7043,25 @@ vect_transform_loop (loop_vec_info loop_vinfo)
/* Reduce loop iterations by the vectorization factor. */
scale_loop_profile (loop, GCOV_COMPUTE_SCALE (1, vf),
expected_iterations / vf);
if (LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo))
{
if (loop->nb_iterations_upper_bound != 0)
loop->nb_iterations_upper_bound = loop->nb_iterations_upper_bound - 1;
if (loop->nb_iterations_likely_upper_bound != 0)
loop->nb_iterations_likely_upper_bound
= loop->nb_iterations_likely_upper_bound - 1;
}
loop->nb_iterations_upper_bound
= wi::udiv_floor (loop->nb_iterations_upper_bound + 1, vf) - 1;
loop->nb_iterations_likely_upper_bound
= wi::udiv_floor (loop->nb_iterations_likely_upper_bound + 1, vf) - 1;
/* The minimum number of iterations performed by the epilogue. This
is 1 when peeling for gaps because we always need a final scalar
iteration. */
int min_epilogue_iters = LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo) ? 1 : 0;
/* +1 to convert latch counts to loop iteration counts,
-min_epilogue_iters to remove iterations that cannot be performed
by the vector code. */
int bias = 1 - min_epilogue_iters;
/* In these calculations the "- 1" converts loop iteration counts
back to latch counts. */
if (loop->any_upper_bound)
loop->nb_iterations_upper_bound
= wi::udiv_floor (loop->nb_iterations_upper_bound + bias, vf) - 1;
if (loop->any_likely_upper_bound)
loop->nb_iterations_likely_upper_bound
= wi::udiv_floor (loop->nb_iterations_likely_upper_bound + bias, vf) - 1;
if (loop->any_estimate)
{
loop->nb_iterations_estimate
= wi::udiv_floor (loop->nb_iterations_estimate, vf);
if (LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo)
&& loop->nb_iterations_estimate != 0)
loop->nb_iterations_estimate = loop->nb_iterations_estimate - 1;
}
loop->nb_iterations_estimate
= wi::udiv_floor (loop->nb_iterations_estimate + bias, vf) - 1;
if (dump_enabled_p ())
{