public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Robin Dapp <rdapp.gcc@gmail.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Cc: rdapp.gcc@gmail.com
Subject: [PATCH] vect: Look through pattern stmt in fold_left_reduction.
Date: Fri, 10 Nov 2023 10:06:11 +0100	[thread overview]
Message-ID: <f8cf4e2c-c172-401f-ab02-a3daa7e2ba74@gmail.com> (raw)

Hi,

more fallout from the COND_OP change was shown in PR112464.

It appears as if we "look through" a statement pattern in
vect_finish_replace_stmt but not before when we replace the newly
created vector statement's lhs.  Then the lhs is the statement pattern's
lhs while in vect_finish_replace_stmt we assert that it's from the
statement the pattern replaced.

This patch uses vect_orig_stmt on the scalar destination's definition
so the replaced statement is used everywhere.

Bootstrapped and regtested on x86 and aarch64, riscv testsuite
unchanged.

Regards
 Robin

gcc/ChangeLog:

	PR tree-optimization/112464

	* tree-vect-loop.cc (vectorize_fold_left_reduction): Use
        vect_orig_stmt on scalar_dest_def_info.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr112464.c: New test.
---
 gcc/testsuite/gcc.target/i386/pr112464.c | 10 ++++++++++
 gcc/tree-vect-loop.cc                    |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr112464.c

diff --git a/gcc/testsuite/gcc.target/i386/pr112464.c b/gcc/testsuite/gcc.target/i386/pr112464.c
new file mode 100644
index 00000000000..2290c714986
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr112464.c
@@ -0,0 +1,10 @@
+/* { dg-do compile }  */
+/* { dg-options "-Ofast -mavx512dq -ftrapv" } */
+
+long *e;
+int n, i, err;
+void fn() {
+  for (; i < n; i++)
+    if (e[i])
+      err++;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 8abc1937d74..f61adad1ca3 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -7087,7 +7087,7 @@ vectorize_fold_left_reduction (loop_vec_info loop_vinfo,
 					 opmask, &vec_opmask);
     }
 
-  gimple *sdef = scalar_dest_def_info->stmt;
+  gimple *sdef = vect_orig_stmt (scalar_dest_def_info)->stmt;
   tree scalar_dest = gimple_get_lhs (sdef);
   tree scalar_type = TREE_TYPE (scalar_dest);
   tree reduc_var = gimple_phi_result (reduc_def_stmt);
-- 
2.41.0

             reply	other threads:[~2023-11-10  9:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-10  9:06 Robin Dapp [this message]
2023-11-10 10:07 ` Richard Biener

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=f8cf4e2c-c172-401f-ab02-a3daa7e2ba74@gmail.com \
    --to=rdapp.gcc@gmail.com \
    --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).