public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r9-8899] openmp: Fix placement of 2nd+ preparation statement for PHIs in simd clone lowering [PR95108]
Date: Wed, 16 Sep 2020 19:22:11 +0000 (GMT)	[thread overview]
Message-ID: <20200916192211.1E260398B83F@sourceware.org> (raw)

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

commit r9-8899-gb78ea59edbd354fed914d0f8eb78109db7316ce8
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu May 14 09:51:05 2020 +0200

    openmp: Fix placement of 2nd+ preparation statement for PHIs in simd clone lowering [PR95108]
    
    For normal stmts, preparation statements are inserted before the stmt, so if we need multiple,
    they are in the correct order, but for PHIs we emit them after labels in the entry successor
    bb, and we used to emit them in the reverse order that way.
    
    2020-05-14  Jakub Jelinek  <jakub@redhat.com>
    
            PR middle-end/95108
            * omp-simd-clone.c (struct modify_stmt_info): Add after_stmt member.
            (ipa_simd_modify_stmt_ops): For PHIs, only add before first stmt in
            entry block if info->after_stmt is NULL, otherwise add after that stmt
            and update it after adding each stmt.
            (ipa_simd_modify_function_body): Initialize info.after_stmt.
    
            * gcc.dg/gomp/pr95108.c: New test.
    
    (cherry picked from commit d0fb9ffc1b8f3b86bbdf0e915cec2136141b329b)

Diff:
---
 gcc/omp-simd-clone.c                | 15 +++++++++++++--
 gcc/testsuite/gcc.dg/gomp/pr95108.c | 18 ++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/gcc/omp-simd-clone.c b/gcc/omp-simd-clone.c
index e865828f569..f403c0a2b9c 100644
--- a/gcc/omp-simd-clone.c
+++ b/gcc/omp-simd-clone.c
@@ -812,6 +812,7 @@ simd_clone_init_simd_arrays (struct cgraph_node *node,
 struct modify_stmt_info {
   ipa_parm_adjustment_vec adjustments;
   gimple *stmt;
+  gimple *after_stmt;
   /* True if the parent statement was modified by
      ipa_simd_modify_stmt_ops.  */
   bool modified;
@@ -892,7 +893,10 @@ ipa_simd_modify_stmt_ops (tree *tp, int *walk_subtrees, void *data)
       gimple_stmt_iterator gsi;
       if (gimple_code (info->stmt) == GIMPLE_PHI)
 	{
-	  gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
+	  if (info->after_stmt)
+	    gsi = gsi_for_stmt (info->after_stmt);
+	  else
+	    gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
 	  /* Cache SSA_NAME for next time.  */
 	  if (cand
 	      && TREE_CODE (*orig_tp) == ADDR_EXPR
@@ -901,7 +905,12 @@ ipa_simd_modify_stmt_ops (tree *tp, int *walk_subtrees, void *data)
 	}
       else
 	gsi = gsi_for_stmt (info->stmt);
-      gsi_insert_before (&gsi, stmt, GSI_SAME_STMT);
+      if (info->after_stmt)
+	gsi_insert_after (&gsi, stmt, GSI_SAME_STMT);
+      else
+	gsi_insert_before (&gsi, stmt, GSI_SAME_STMT);
+      if (gimple_code (info->stmt) == GIMPLE_PHI)
+	info->after_stmt = stmt;
       *orig_tp = repl;
     }
   else if (!useless_type_conversion_p (TREE_TYPE (*tp), TREE_TYPE (repl)))
@@ -1006,6 +1015,7 @@ ipa_simd_modify_function_body (struct cgraph_node *node,
 	  gphi *phi = as_a <gphi *> (gsi_stmt (gsi));
 	  int i, n = gimple_phi_num_args (phi);
 	  info.stmt = phi;
+	  info.after_stmt = NULL;
 	  struct walk_stmt_info wi;
 	  memset (&wi, 0, sizeof (wi));
 	  info.modified = false;
@@ -1031,6 +1041,7 @@ ipa_simd_modify_function_body (struct cgraph_node *node,
 	{
 	  gimple *stmt = gsi_stmt (gsi);
 	  info.stmt = stmt;
+	  info.after_stmt = NULL;
 	  struct walk_stmt_info wi;
 
 	  memset (&wi, 0, sizeof (wi));
diff --git a/gcc/testsuite/gcc.dg/gomp/pr95108.c b/gcc/testsuite/gcc.dg/gomp/pr95108.c
new file mode 100644
index 00000000000..b492333686b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gomp/pr95108.c
@@ -0,0 +1,18 @@
+/* PR middle-end/95108 */
+/* { dg-do compile { target vect_simd_clones } } */
+/* { dg-options "-O2 -fopenmp-simd -w" } */
+
+int *v;
+
+#pragma omp declare simd
+void
+foo (int x)
+{
+  int *a = &x + 1;
+
+  for (;;)
+    {
+      *v = *a;
+      a = v;
+    }
+}


                 reply	other threads:[~2020-09-16 19:22 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=20200916192211.1E260398B83F@sourceware.org \
    --to=jakub@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).