[PATCH 1v2/3][vect] Add main vectorized loop unrolling
Richard Biener
rguenther@suse.de
Fri Nov 12 13:12:59 GMT 2021
On Thu, 11 Nov 2021, Andre Vieira (lists) wrote:
> Hi,
>
> This is the rebased and reworked version of the unroll patch. I wasn't
> entirely sure whether I should compare the costs of the unrolled loop_vinfo
> with the original loop_vinfo it was unrolled of. I did now, but I wasn't too
> sure whether it was a good idea to... Any thoughts on this?
+ /* Apply the suggested unrolling factor, this was determined by the
backend
+ during finish_cost the first time we ran the analyzis for this
+ vector mode. */
+ if (loop_vinfo->suggested_unroll_factor > 1)
+ {
+ poly_uint64 unrolled_vf
+ = LOOP_VINFO_VECT_FACTOR (loop_vinfo) *
loop_vinfo->suggested_unroll_factor;
+ /* Make sure the unrolled vectorization factor is less than the max
+ vectorization factor. */
+ unsigned HOST_WIDE_INT max_vf = LOOP_VINFO_MAX_VECT_FACTOR
(loop_vinfo);
+ if (max_vf == MAX_VECTORIZATION_FACTOR || known_le (unrolled_vf,
max_vf))
+ LOOP_VINFO_VECT_FACTOR (loop_vinfo) = unrolled_vf;
+ else
+ return opt_result::failure_at (vect_location,
+ "unrolling failed: unrolled"
+ " vectorization factor larger than"
+ " maximum vectorization factor:
%d\n",
+ LOOP_VINFO_MAX_VECT_FACTOR
(loop_vinfo));
+ }
+
/* This is the point where we can re-start analysis with SLP forced
off. */
start_over:
So we're honoring suggested_unroll_factor here but you still have the
now unused hunk
+vect_analyze_loop_2 (loop_vec_info loop_vinfo, bool &fatal,
+ unsigned *suggested_unroll_factor, poly_uint64 min_vf
= 2)
{
I also wonder whether vect_analyze_loop_2 could at least prune
suggested_unroll_factor as set by vect_analyze_loop_costing with its
knowledge of max_vf itself? That would avoid using the at the moment
unused LOOP_VINFO_MAX_VECT_FACTOR?
I think all the things you do in vect_can_unroll should be figured
out with the re-analysis, and I'd just amend vect_analyze_loop_1
with a suggested unroll factor parameter like it has main_loop_vinfo
for the epilogue case. The main loop adjustment would the be in the
if (first_loop_vinfo == NULL)
{
first_loop_vinfo = loop_vinfo;
first_loop_i = loop_vinfo_i;
first_loop_next_i = mode_i;
}
spot only, adding
if (loop_vinfo->suggested_unroll_factor != 1)
{
suggested_unroll_factor = loop_vinfo->suggested_unroll_factor;
mode_i = first_loop_i;
if (dump)
dump_print ("Trying unrolling by %d\n");
continue;
}
and a reset of suggested_unroll_factor after the vect_analyze_loop_1
call? (that's basically pushing another analysis case to the
poor-mans "worklist")
Richard.
> Regards,
>
> Andre
>
>
> gcc/ChangeLog:
>
> * tree-vect-loop.c (vect_estimate_min_profitable_iters): Add
> suggested_unroll_factor parameter.
> (vect_analyze_loop_costing): Likewise.
> (vect_determine_partial_vectors_and_peeling): Don't mask an
> unrolled loop.
> (vect_analyze_loop_2): Support unrolling of loops.
> (vect_can_unroll): New function.
> (vect_try_unrolling): New function.
> (vect_analyze_loop_1): Add suggested_unroll_factor parameter
> and use it.
> (vect_analyze_loop): Call vect_try_unrolling when unrolling suggested.
> (vectorizable_reduction): Don't single_defuse_cycle when unrolling.
> * tree-vectorizer.h (_loop_vec_info::_loop_vec_info): Add
> suggested_unroll_factor member.
> (vector_costs::vector_costs): Add m_suggested_unroll_factor member.
> (vector_costs::suggested_unroll_factor): New getter.
> (finish_cost): Add suggested_unroll_factor out parameter and
> set it.
>
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imend
More information about the Gcc-patches
mailing list