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 r13-5089] tree-optimization/108314 - avoid BIT_NOT optimization for extract-last
Date: Tue, 10 Jan 2023 12:08:46 +0000 (GMT)	[thread overview]
Message-ID: <20230110120846.ECD903858CDA@sourceware.org> (raw)

https://gcc.gnu.org/g:554bb9b61e2b76d4ace16a3f766b98ea887b17f4

commit r13-5089-g554bb9b61e2b76d4ace16a3f766b98ea887b17f4
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Jan 10 10:42:21 2023 +0100

    tree-optimization/108314 - avoid BIT_NOT optimization for extract-last
    
    The extract-last reduction internal function expects the then and
    else clause as vector and scalar and thus we cannot perform optimization
    of the inversion of the condition by swapping the then/else clauses.
    
            PR tree-optimization/108314
            * tree-vect-stmts.cc (vectorizable_condition): Do not
            perform BIT_NOT_EXPR optimization for EXTRACT_LAST_REDUCTION.
    
            * gcc.dg/vect/pr108314.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr108314.c | 16 ++++++++++++++++
 gcc/tree-vect-stmts.cc               | 13 +++++++++----
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr108314.c b/gcc/testsuite/gcc.dg/vect/pr108314.c
new file mode 100644
index 00000000000..07260e06915
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr108314.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=armv9-a" { target aarch64-*-* } } */
+
+int x, y, z;
+
+void f(void)
+{
+  int t = 4;
+  for (; x; x++)
+    {
+      if (y)
+	continue;
+      t = 0;
+    }
+  z = t;
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 6ddd41fb473..eb4ca1f184e 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -10677,7 +10677,8 @@ vectorizable_condition (vec_info *vinfo,
 	      vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
 	      if (bitop2 == NOP_EXPR)
 		vec_compare = new_temp;
-	      else if (bitop2 == BIT_NOT_EXPR)
+	      else if (bitop2 == BIT_NOT_EXPR
+		       && reduction_type != EXTRACT_LAST_REDUCTION)
 		{
 		  /* Instead of doing ~x ? y : z do x ? z : y.  */
 		  vec_compare = new_temp;
@@ -10686,9 +10687,13 @@ vectorizable_condition (vec_info *vinfo,
 	      else
 		{
 		  vec_compare = make_ssa_name (vec_cmp_type);
-		  new_stmt
-		    = gimple_build_assign (vec_compare, bitop2,
-					   vec_cond_lhs, new_temp);
+		  if (bitop2 == BIT_NOT_EXPR)
+		    new_stmt
+		      = gimple_build_assign (vec_compare, bitop2, new_temp);
+		  else
+		    new_stmt
+		      = gimple_build_assign (vec_compare, bitop2,
+					     vec_cond_lhs, new_temp);
 		  vect_finish_stmt_generation (vinfo, stmt_info,
 					       new_stmt, gsi);
 		}

                 reply	other threads:[~2023-01-10 12:08 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=20230110120846.ECD903858CDA@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).