From: Richard Sandiford <richard.sandiford@arm.com>
To: "Andre Vieira \(lists\) via Gcc-patches" <gcc-patches@gcc.gnu.org>
Cc: "Andre Vieira \(lists\)" <andre.simoesdiasvieira@arm.com>,
Richard Biener <rguenther@suse.de>
Subject: Re: [PATCH 2/3][vect] Consider outside costs earlier for epilogue loops
Date: Fri, 22 Oct 2021 16:33:45 +0100 [thread overview]
Message-ID: <mptsfwtul9i.fsf@arm.com> (raw)
In-Reply-To: <4b403865-bb56-29a4-56d0-b18536925db6@arm.com> (Andre Vieira via Gcc-patches's message of "Fri, 17 Sep 2021 16:32:48 +0100")
"Andre Vieira (lists) via Gcc-patches" <gcc-patches@gcc.gnu.org> writes:
> Hi,
>
> This patch changes the order in which we check outside and inside costs
> for epilogue loops, this is to ensure that a predicated epilogue is more
> likely to be picked over an unpredicated one, since it saves having to
> enter a scalar epilogue loop.
>
> gcc/ChangeLog:
>
> * tree-vect-loop.c (vect_better_loop_vinfo_p): Change how
> epilogue loop costs are compared.
OK, thanks. Sorry for the slow review.
Richard
> diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
> index 14f8150d7c262b9422784e0e997ca4387664a20a..038af13a91d43c9f09186d042cf415020ea73a38 100644
> --- a/gcc/tree-vect-loop.c
> +++ b/gcc/tree-vect-loop.c
> @@ -2881,17 +2881,75 @@ vect_better_loop_vinfo_p (loop_vec_info new_loop_vinfo,
> return new_simdlen_p;
> }
>
> + loop_vec_info main_loop = LOOP_VINFO_ORIG_LOOP_INFO (old_loop_vinfo);
> + if (main_loop)
> + {
> + poly_uint64 main_poly_vf = LOOP_VINFO_VECT_FACTOR (main_loop);
> + unsigned HOST_WIDE_INT main_vf;
> + unsigned HOST_WIDE_INT old_factor, new_factor, old_cost, new_cost;
> + /* If we can determine how many iterations are left for the epilogue
> + loop, that is if both the main loop's vectorization factor and number
> + of iterations are constant, then we use them to calculate the cost of
> + the epilogue loop together with a 'likely value' for the epilogues
> + vectorization factor. Otherwise we use the main loop's vectorization
> + factor and the maximum poly value for the epilogue's. If the target
> + has not provided with a sensible upper bound poly vectorization
> + factors are likely to be favored over constant ones. */
> + if (main_poly_vf.is_constant (&main_vf)
> + && LOOP_VINFO_NITERS_KNOWN_P (main_loop))
> + {
> + unsigned HOST_WIDE_INT niters
> + = LOOP_VINFO_INT_NITERS (main_loop) % main_vf;
> + HOST_WIDE_INT old_likely_vf
> + = estimated_poly_value (old_vf, POLY_VALUE_LIKELY);
> + HOST_WIDE_INT new_likely_vf
> + = estimated_poly_value (new_vf, POLY_VALUE_LIKELY);
> +
> + /* If the epilogue is using partial vectors we account for the
> + partial iteration here too. */
> + old_factor = niters / old_likely_vf;
> + if (LOOP_VINFO_USING_PARTIAL_VECTORS_P (old_loop_vinfo)
> + && niters % old_likely_vf != 0)
> + old_factor++;
> +
> + new_factor = niters / new_likely_vf;
> + if (LOOP_VINFO_USING_PARTIAL_VECTORS_P (new_loop_vinfo)
> + && niters % new_likely_vf != 0)
> + new_factor++;
> + }
> + else
> + {
> + unsigned HOST_WIDE_INT main_vf_max
> + = estimated_poly_value (main_poly_vf, POLY_VALUE_MAX);
> +
> + old_factor = main_vf_max / estimated_poly_value (old_vf,
> + POLY_VALUE_MAX);
> + new_factor = main_vf_max / estimated_poly_value (new_vf,
> + POLY_VALUE_MAX);
> +
> + /* If the loop is not using partial vectors then it will iterate one
> + time less than one that does. It is safe to subtract one here,
> + because the main loop's vf is always at least 2x bigger than that
> + of an epilogue. */
> + if (!LOOP_VINFO_USING_PARTIAL_VECTORS_P (old_loop_vinfo))
> + old_factor -= 1;
> + if (!LOOP_VINFO_USING_PARTIAL_VECTORS_P (new_loop_vinfo))
> + new_factor -= 1;
> + }
> +
> + /* Compute the costs by multiplying the inside costs with the factor and
> + add the outside costs for a more complete picture. The factor is the
> + amount of times we are expecting to iterate this epilogue. */
> + old_cost = old_loop_vinfo->vec_inside_cost * old_factor;
> + new_cost = new_loop_vinfo->vec_inside_cost * new_factor;
> + old_cost += old_loop_vinfo->vec_outside_cost;
> + new_cost += new_loop_vinfo->vec_outside_cost;
> + return new_cost < old_cost;
> + }
> +
> /* Limit the VFs to what is likely to be the maximum number of iterations,
> to handle cases in which at least one loop_vinfo is fully-masked. */
> - HOST_WIDE_INT estimated_max_niter;
> - loop_vec_info main_loop = LOOP_VINFO_ORIG_LOOP_INFO (old_loop_vinfo);
> - unsigned HOST_WIDE_INT main_vf;
> - if (main_loop
> - && LOOP_VINFO_NITERS_KNOWN_P (main_loop)
> - && LOOP_VINFO_VECT_FACTOR (main_loop).is_constant (&main_vf))
> - estimated_max_niter = LOOP_VINFO_INT_NITERS (main_loop) % main_vf;
> - else
> - estimated_max_niter = likely_max_stmt_executions_int (loop);
> + HOST_WIDE_INT estimated_max_niter = likely_max_stmt_executions_int (loop);
> if (estimated_max_niter != -1)
> {
> if (known_le (estimated_max_niter, new_vf))
prev parent reply other threads:[~2021-10-22 15:33 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-17 15:27 [PATCH 0/3][vect] Enable vector unrolling of main loop Andre Vieira (lists)
2021-09-17 15:31 ` [PATCH 1/3][vect] Add main vectorized loop unrolling Andre Vieira (lists)
2021-09-21 12:30 ` Richard Biener
2021-09-21 16:34 ` Andre Vieira (lists)
2021-09-22 6:14 ` Richard Biener
2021-09-30 8:52 ` [PATCH 1v2/3][vect] " Andre Vieira (lists)
2021-10-01 8:19 ` Richard Biener
2021-10-04 16:30 ` Richard Sandiford
2021-10-12 10:35 ` Andre Vieira (lists)
2021-10-15 8:48 ` Richard Biener
2021-10-20 13:29 ` Andre Vieira (lists)
2021-10-21 12:14 ` Richard Biener
2021-10-22 10:18 ` Richard Sandiford
2021-11-11 16:02 ` Andre Vieira (lists)
2021-11-12 13:12 ` Richard Biener
2021-11-22 11:41 ` Andre Vieira (lists)
2021-11-22 12:39 ` Richard Biener
2021-11-24 9:46 ` Andre Vieira (lists)
2021-11-24 11:00 ` Richard Biener
2021-11-25 10:40 ` Andre Vieira (lists)
2021-11-25 12:46 ` Richard Biener
2021-11-30 11:36 ` Andre Vieira (lists)
2021-11-30 13:56 ` Richard Biener
2021-12-07 11:27 ` [vect] Re-analyze all modes for epilogues Andre Vieira (lists)
2021-12-07 11:31 ` Andre Vieira (lists)
2021-12-07 11:48 ` Richard Biener
2021-12-07 13:31 ` Richard Sandiford
2021-12-07 13:33 ` Richard Biener
2021-12-07 11:45 ` Richard Biener
2021-12-07 15:17 ` Andre Vieira (lists)
2021-12-13 16:41 ` Andre Vieira (lists)
2021-12-14 11:39 ` Richard Sandiford
2021-12-17 16:33 ` Andre Vieira (lists)
2022-01-07 12:39 ` Richard Sandiford
2022-01-10 18:31 ` [PATCH 1v2/3][vect] Add main vectorized loop unrolling Andre Vieira (lists)
2022-01-11 7:14 ` Richard Biener
2021-10-22 10:12 ` Richard Sandiford
2021-09-17 15:32 ` [PATCH 2/3][vect] Consider outside costs earlier for epilogue loops Andre Vieira (lists)
2021-10-14 13:44 ` Andre Vieira (lists)
2021-10-22 15:33 ` Richard Sandiford [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=mptsfwtul9i.fsf@arm.com \
--to=richard.sandiford@arm.com \
--cc=andre.simoesdiasvieira@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=rguenther@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).