From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/107160 - avoid reusing multiple accumulators
Date: Thu, 13 Oct 2022 15:16:31 +0200 (CEST) [thread overview]
Message-ID: <20221013131632.1017D13AAA@imap2.suse-dmz.suse.de> (raw)
Epilogue vectorization is not set up to re-use a vectorized
accumulator consisting of more than one vector. For non-SLP
we always reduce to a single but for SLP that isn't happening.
In such case we currenlty miscompile the epilog so avoid this.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR tree-optimization/107160
* tree-vect-loop.cc (vect_create_epilog_for_reduction):
Do not register accumulator if we failed to reduce it
to a single vector.
* gcc.dg/vect/pr107160.c: New testcase.
---
gcc/testsuite/gcc.dg/vect/pr107160.c | 41 ++++++++++++++++++++++++++++
gcc/tree-vect-loop.cc | 3 +-
2 files changed, 43 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/vect/pr107160.c
diff --git a/gcc/testsuite/gcc.dg/vect/pr107160.c b/gcc/testsuite/gcc.dg/vect/pr107160.c
new file mode 100644
index 00000000000..4f9f853cafb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr107160.c
@@ -0,0 +1,41 @@
+/* { dg-do run } */
+
+#include <math.h>
+
+#define N 128
+float fl[N];
+
+__attribute__ ((noipa)) void
+init ()
+{
+ for (int i = 0; i < N; i++)
+ fl[i] = i;
+}
+
+__attribute__ ((noipa)) float
+foo (int n1)
+{
+ float sum0, sum1, sum2, sum3;
+ sum0 = sum1 = sum2 = sum3 = 0.0f;
+
+ int n = (n1 / 4) * 4;
+ for (int i = 0; i < n; i += 4)
+ {
+ sum0 += fabs (fl[i]);
+ sum1 += fabs (fl[i + 1]);
+ sum2 += fabs (fl[i + 2]);
+ sum3 += fabs (fl[i + 3]);
+ }
+
+ return sum0 + sum1 + sum2 + sum3;
+}
+
+int
+main ()
+{
+ init ();
+ float res = foo (80);
+ if (res != 3160)
+ __builtin_abort ();
+ return 0;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 1996ecfee7a..b1442a93581 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -6232,7 +6232,8 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
}
/* Record this operation if it could be reused by the epilogue loop. */
- if (STMT_VINFO_REDUC_TYPE (reduc_info) == TREE_CODE_REDUCTION)
+ if (STMT_VINFO_REDUC_TYPE (reduc_info) == TREE_CODE_REDUCTION
+ && vec_num == 1)
loop_vinfo->reusable_accumulators.put (scalar_results[0],
{ orig_reduc_input, reduc_info });
--
2.35.3
reply other threads:[~2022-10-13 13:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20221013131632.1017D13AAA@imap2.suse-dmz.suse.de \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
/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).