public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-10012] tree-optimization/111764 - wrong reduction vectorization
Date: Mon, 27 Nov 2023 13:09:47 +0000 (GMT)	[thread overview]
Message-ID: <20231127130947.9C38538582B8@sourceware.org> (raw)

https://gcc.gnu.org/g:bd75062cc3fc4abd19c37fae164d9764ffab2407

commit r12-10012-gbd75062cc3fc4abd19c37fae164d9764ffab2407
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Oct 12 09:09:46 2023 +0200

    tree-optimization/111764 - wrong reduction vectorization
    
    The following removes a misguided attempt to allow x + x in a reduction
    path, also allowing x * x which isn't valid.  x + x actually never
    arrives this way but instead is canonicalized to 2 * x.  This makes
    reduction path handling consistent with how we handle the single-stmt
    reduction case.
    
            PR tree-optimization/111764
            * tree-vect-loop.cc (check_reduction_path): Remove the attempt
            to allow x + x via special-casing of assigns.
    
            * gcc.dg/vect/pr111764.c: New testcase.
    
    (cherry picked from commit 05f98310b54da95e468d799f4a910174320cccbb)

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr111764.c | 16 ++++++++++++++++
 gcc/tree-vect-loop.cc                | 15 +++------------
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr111764.c b/gcc/testsuite/gcc.dg/vect/pr111764.c
new file mode 100644
index 00000000000..f4e110f3bbf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr111764.c
@@ -0,0 +1,16 @@
+#include "tree-vect.h"
+
+short b = 2;
+
+int main()
+{
+  check_vect ();
+
+  for (int a = 1; a <= 9; a++)
+    b = b * b;
+  if (b != 0)
+    __builtin_abort ();
+
+  return 0;
+}
+
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 9df2d5690b7..e1681047d9d 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -3513,24 +3513,15 @@ pop:
 	 ???  We could relax this and handle arbitrary live stmts by
 	 forcing a scalar epilogue for example.  */
       imm_use_iterator imm_iter;
+      use_operand_p use_p;
       gimple *op_use_stmt;
       unsigned cnt = 0;
       FOR_EACH_IMM_USE_STMT (op_use_stmt, imm_iter, op.ops[opi])
 	if (!is_gimple_debug (op_use_stmt)
 	    && (*code != ERROR_MARK
 		|| flow_bb_inside_loop_p (loop, gimple_bb (op_use_stmt))))
-	  {
-	    /* We want to allow x + x but not x < 1 ? x : 2.  */
-	    if (is_gimple_assign (op_use_stmt)
-		&& gimple_assign_rhs_code (op_use_stmt) == COND_EXPR)
-	      {
-		use_operand_p use_p;
-		FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
-		  cnt++;
-	      }
-	    else
-	      cnt++;
-	  }
+	  FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
+	    cnt++;
       if (cnt != 1)
 	{
 	  fail = true;

                 reply	other threads:[~2023-11-27 13:09 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=20231127130947.9C38538582B8@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@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).