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/109025 - fixup double reduction detection
Date: Mon, 6 Mar 2023 11:26:08 +0100 (CET)	[thread overview]
Message-ID: <20230306102609.1310C13A66@imap2.suse-dmz.suse.de> (raw)

The following closes a gap in double reduction detection where we
in the outer loop analysis fail to verify the inner LC PHI use is
the latch definition of the inner loop PHI.  That latch definition
is used to detect that an inner loop is part of a double reduction
when later doing the inner loop analysis.

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

	PR tree-optimization/109025
	* tree-vect-loop.cc (vect_is_simple_reduction): Verify
	the inner LC PHI use is the inner loop PHI latch definition
	before classifying an outer PHI as double reduction.

	* gcc.dg/vect/pr109025.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/pr109025.c | 14 ++++++++++++++
 gcc/tree-vect-loop.cc                |  6 +++++-
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr109025.c

diff --git a/gcc/testsuite/gcc.dg/vect/pr109025.c b/gcc/testsuite/gcc.dg/vect/pr109025.c
new file mode 100644
index 00000000000..13fb0ce4ba9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr109025.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O3" } */
+
+int func_4(int t, int b)
+{
+  for (int tt1 = 0; tt1 < 128 ; tt1 ++)
+    {
+      for (int tt = 0; tt < 128; tt ++)
+	if (b)
+	  t |= 3;
+      t |= 3;
+    }
+  return t;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index b17e8745d3f..320c15f144b 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -3894,6 +3894,8 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info,
           return NULL;
         }
 
+      /* Verify there is an inner cycle composed of the PHI phi_use_stmt
+	 and the latch definition op1.  */
       gimple *def1 = SSA_NAME_DEF_STMT (op1);
       if (gimple_bb (def1)
 	  && flow_bb_inside_loop_p (loop, gimple_bb (def_stmt))
@@ -3901,7 +3903,9 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info,
 	  && flow_bb_inside_loop_p (loop->inner, gimple_bb (def1))
 	  && (is_gimple_assign (def1) || is_gimple_call (def1))
 	  && is_a <gphi *> (phi_use_stmt)
-	  && flow_bb_inside_loop_p (loop->inner, gimple_bb (phi_use_stmt)))
+	  && flow_bb_inside_loop_p (loop->inner, gimple_bb (phi_use_stmt))
+	  && (op1 == PHI_ARG_DEF_FROM_EDGE (phi_use_stmt,
+					    loop_latch_edge (loop->inner))))
         {
           if (dump_enabled_p ())
             report_vect_op (MSG_NOTE, def_stmt,
-- 
2.35.3

                 reply	other threads:[~2023-03-06 10:26 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=20230306102609.1310C13A66@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).