From: Richard Sandiford <richard.sandiford@arm.com>
To: Richard Biener <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org, amonakov@ispras.ru
Subject: Re: [PATCH] tree-optimization/110979 - fold-left reduction and partial vectors
Date: Fri, 11 Aug 2023 12:45:49 +0100 [thread overview]
Message-ID: <mpto7jdssya.fsf@arm.com> (raw)
In-Reply-To: <20230811110606.08A7913592@imap2.suse-dmz.suse.de> (Richard Biener's message of "Fri, 11 Aug 2023 13:06:05 +0200 (CEST)")
Richard Biener <rguenther@suse.de> writes:
> When we vectorize fold-left reductions with partial vectors but
> no target operation available we use a vector conditional to force
> excess elements to zero. But that doesn't correctly preserve
> the sign of zero. The following patch disables partial vector
> support in that case.
>
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
>
> Does this look OK?
LGTM.
> With -frounding-math -fno-signed-zeros we are
> happily using the masking again, but that's OK, right? An additional
> + 0.0 shouldn't do anything here.
Yeah, I would hope so.
Thanks,
Richard
>
> Thanks,
> Richard.
>
> PR tree-optimization/110979
> * tree-vect-loop.cc (vectorizable_reduction): For
> FOLD_LEFT_REDUCTION without target support make sure
> we don't need to honor signed zeros.
>
> * gcc.dg/torture/pr110979.c: New testcase.
> ---
> gcc/testsuite/gcc.dg/torture/pr110979.c | 25 +++++++++++++++++++++++++
> gcc/tree-vect-loop.cc | 11 +++++++++++
> 2 files changed, 36 insertions(+)
> create mode 100644 gcc/testsuite/gcc.dg/torture/pr110979.c
>
> diff --git a/gcc/testsuite/gcc.dg/torture/pr110979.c b/gcc/testsuite/gcc.dg/torture/pr110979.c
> new file mode 100644
> index 00000000000..c25ad7a8a31
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/torture/pr110979.c
> @@ -0,0 +1,25 @@
> +/* { dg-do run } */
> +/* { dg-additional-options "--param vect-partial-vector-usage=2" } */
> +
> +#define FLT double
> +#define N 20
> +
> +__attribute__((noipa))
> +FLT
> +foo3 (FLT *a)
> +{
> + FLT sum = -0.0;
> + for (int i = 0; i != N; i++)
> + sum += a[i];
> + return sum;
> +}
> +
> +int main()
> +{
> + FLT a[N];
> + for (int i = 0; i != N; i++)
> + a[i] = -0.0;
> + if (!__builtin_signbit(foo3(a)))
> + __builtin_abort();
> + return 0;
> +}
> diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
> index bf8d677b584..741b5c20389 100644
> --- a/gcc/tree-vect-loop.cc
> +++ b/gcc/tree-vect-loop.cc
> @@ -8037,6 +8037,17 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
> " no conditional operation is available.\n");
> LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
> }
> + else if (reduction_type == FOLD_LEFT_REDUCTION
> + && reduc_fn == IFN_LAST
> + && FLOAT_TYPE_P (vectype_in)
> + && HONOR_SIGNED_ZEROS (vectype_in))
> + {
> + if (dump_enabled_p ())
> + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
> + "can't operate on partial vectors because"
> + " signed zeros need to be handled.\n");
> + LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
> + }
> else
> {
> internal_fn mask_reduc_fn
prev parent reply other threads:[~2023-08-11 11:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-11 11:06 Richard Biener
2023-08-11 11:24 ` Alexander Monakov
2023-08-11 12:11 ` Richard Biener
2023-08-11 13:34 ` Alexander Monakov
2023-08-11 11:45 ` 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=mpto7jdssya.fsf@arm.com \
--to=richard.sandiford@arm.com \
--cc=amonakov@ispras.ru \
--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).