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/113431 - wrong dependence with invariant load
Date: Thu, 18 Jan 2024 08:31:04 +0100 (CET)	[thread overview]
Message-ID: <20240118073104.h8mQBPxZNU_Je68V530G8xdhhy9K2YNgXHXUDD3EI7g@z> (raw)

The vectorizer dependence analysis is confused with invariant loads
when figuring whether the circumstances are so that we preserve
scalar stmt execution order.  The following rectifies this.

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

	PR tree-optimization/113431
	* tree-vect-data-refs.cc (vect_preserves_scalar_order_p):
	When there is an invariant load we might not preserve
	scalar order.

	* gcc.dg/vect/pr113431.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/pr113431.c | 18 ++++++++++++++++++
 gcc/tree-vect-data-refs.cc           |  6 ++++++
 2 files changed, 24 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr113431.c

diff --git a/gcc/testsuite/gcc.dg/vect/pr113431.c b/gcc/testsuite/gcc.dg/vect/pr113431.c
new file mode 100644
index 00000000000..04448d9dd81
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr113431.c
@@ -0,0 +1,18 @@
+/* { dg-additional-options "-O3 -fdump-tree-slp1-details" } */
+
+#include "tree-vect.h"
+
+int a[2][9];
+int b;
+int main()
+{
+  check_vect ();
+  for (b = 0; b < 2; b++)
+    for (long e = 8; e > 0; e--)
+      a[b][e] = a[0][1] == 0;
+  if (a[1][1] != 0)
+    __builtin_abort ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "optimized: basic block part vectorized" 2 "slp1" { target vect_int } } } */
diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc
index 0495842b350..f592aeb8028 100644
--- a/gcc/tree-vect-data-refs.cc
+++ b/gcc/tree-vect-data-refs.cc
@@ -282,6 +282,12 @@ vect_preserves_scalar_order_p (dr_vec_info *dr_info_a, dr_vec_info *dr_info_b)
       && !STMT_VINFO_GROUPED_ACCESS (stmtinfo_b))
     return true;
 
+  /* If there is a loop invariant read involved we might vectorize it in
+     the prologue, breaking scalar oder with respect to the in-loop store.  */
+  if ((DR_IS_READ (dr_info_a->dr) && integer_zerop (DR_STEP (dr_info_a->dr)))
+      || (DR_IS_READ (dr_info_b->dr) && integer_zerop (DR_STEP (dr_info_b->dr))))
+    return false;
+
   /* STMT_A and STMT_B belong to overlapping groups.  All loads are
      emitted at the position of the first scalar load.
      Stores in a group are emitted at the position of the last scalar store.
-- 
2.35.3

                 reply	other threads:[~2024-01-18  7:36 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=20240118073104.h8mQBPxZNU_Je68V530G8xdhhy9K2YNgXHXUDD3EI7g@z \
    --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).