aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-05-14 09:51:05 +0200
committerJakub Jelinek <jakub@redhat.com>2020-05-14 09:51:05 +0200
commitd0fb9ffc1b8f3b86bbdf0e915cec2136141b329b (patch)
tree6134d68b15fcb5d6601caaaa82290e0bd000b2be /gcc
parent49ddde69fc8e1e4c48d4b0027ea37ac862da0f1f (diff)
downloadgcc-d0fb9ffc1b8f3b86bbdf0e915cec2136141b329b.zip
gcc-d0fb9ffc1b8f3b86bbdf0e915cec2136141b329b.tar.gz
gcc-d0fb9ffc1b8f3b86bbdf0e915cec2136141b329b.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/omp-simd-clone.c15
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/gomp/pr95108.c18
4 files changed, 43 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ce5ccab..0f0dbd0 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
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.
+
* function.h (struct function): Add has_omp_target bit.
* omp-offload.c (omp_discover_declare_target_fn_r): New function,
old renamed to ...
diff --git a/gcc/omp-simd-clone.c b/gcc/omp-simd-clone.c
index 71ff034..09fdd60 100644
--- a/gcc/omp-simd-clone.c
+++ b/gcc/omp-simd-clone.c
@@ -821,6 +821,7 @@ simd_clone_init_simd_arrays (struct cgraph_node *node,
struct modify_stmt_info {
ipa_param_body_adjustments *adjustments;
gimple *stmt;
+ gimple *after_stmt;
/* True if the parent statement was modified by
ipa_simd_modify_stmt_ops. */
bool modified;
@@ -912,7 +913,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 (pbr
&& TREE_CODE (*orig_tp) == ADDR_EXPR
@@ -924,7 +928,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)))
@@ -1015,6 +1024,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;
@@ -1040,6 +1050,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/ChangeLog b/gcc/testsuite/ChangeLog
index 2c96a24..13d5548 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-05-14 Jakub Jelinek <jakub@redhat.com>
+
+ PR middle-end/95108
+ * gcc.dg/gomp/pr95108.c: New test.
+
2020-05-14 Uroš Bizjak <ubizjak@gmail.com>
PR target/95046
diff --git a/gcc/testsuite/gcc.dg/gomp/pr95108.c b/gcc/testsuite/gcc.dg/gomp/pr95108.c
new file mode 100644
index 0000000..b492333
--- /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;
+ }
+}