public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/108782 - nested first order recurrence vectorization
Date: Tue, 14 Feb 2023 12:49:17 +0100 (CET)	[thread overview]
Message-ID: <20230214114918.3E86413A21@imap2.suse-dmz.suse.de> (raw)

First order recurrence vectorization isn't possible for nested
loops.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/108782
	* tree-vect-loop.cc (vect_phi_first_order_recurrence_p):
	Make sure we're not vectorizing an inner loop.

	* gcc.dg/torture/pr108782.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr108782.c | 21 +++++++++++++++++++++
 gcc/tree-vect-loop.cc                   |  4 ++++
 2 files changed, 25 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr108782.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr108782.c b/gcc/testsuite/gcc.dg/torture/pr108782.c
new file mode 100644
index 00000000000..1eac93db574
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr108782.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fno-tree-copy-prop" } */
+
+int m;
+
+__attribute__ ((simd)) int
+foo (void)
+{
+  unsigned a;
+  int b = 0;
+
+  m = a = 1;
+  while (a != 0)
+    {
+      b = m;
+      m = 2;
+      ++a;
+    }
+
+  return b;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index becf96bb2b8..8387f7690b2 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -538,6 +538,10 @@ static bool
 vect_phi_first_order_recurrence_p (loop_vec_info loop_vinfo, class loop *loop,
 				   gphi *phi)
 {
+  /* A nested cycle isn't vectorizable as first order recurrence.  */
+  if (LOOP_VINFO_LOOP (loop_vinfo) != loop)
+    return false;
+
   /* Ensure the loop latch definition is from within the loop.  */
   edge latch = loop_latch_edge (loop);
   tree ldef = PHI_ARG_DEF_FROM_EDGE (phi, latch);
-- 
2.35.3

                 reply	other threads:[~2023-02-14 11:49 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=20230214114918.3E86413A21@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).