public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5295] openmp: Regimplify operands of GIMPLE_COND in a few more places [PR103208]
@ 2021-11-16 9:21 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-11-16 9:21 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:47de0b56ee455ec82ec7d61a20988f11b67aa4e9
commit r12-5295-g47de0b56ee455ec82ec7d61a20988f11b67aa4e9
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Nov 16 10:19:22 2021 +0100
openmp: Regimplify operands of GIMPLE_COND in a few more places [PR103208]
As the testcase shows, the non-rectangular loop expansion code didn't
try to regimplify operands of GIMPLE_CONDs it built in some cases.
I have added a helper function which does that and used it in some places
that were regimplifying already to simplify those spots, plus added it
in a couple of other places where it was needed.
2021-11-16 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/103208
* omp-expand.c (expand_omp_build_cond): New function.
(expand_omp_for_init_counts, expand_omp_for_init_vars,
expand_omp_for_static_nochunk, expand_omp_for_static_chunk): Use it.
* c-c++-common/gomp/loop-11.c: New test.
Diff:
---
gcc/omp-expand.c | 102 +++++++++++++-----------------
gcc/testsuite/c-c++-common/gomp/loop-11.c | 5 ++
2 files changed, 48 insertions(+), 59 deletions(-)
diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c
index 1a5426e3517..c5fa5a01aac 100644
--- a/gcc/omp-expand.c
+++ b/gcc/omp-expand.c
@@ -1208,6 +1208,28 @@ expand_omp_build_assign (gimple_stmt_iterator *gsi_p, tree to, tree from,
}
}
+/* Prepend or append LHS CODE RHS condition before or after *GSI_P. */
+
+static gcond *
+expand_omp_build_cond (gimple_stmt_iterator *gsi_p, enum tree_code code,
+ tree lhs, tree rhs, bool after = false)
+{
+ gcond *cond_stmt = gimple_build_cond (code, lhs, rhs, NULL_TREE, NULL_TREE);
+ if (after)
+ gsi_insert_after (gsi_p, cond_stmt, GSI_CONTINUE_LINKING);
+ else
+ gsi_insert_before (gsi_p, cond_stmt, GSI_SAME_STMT);
+ if (walk_tree (gimple_cond_lhs_ptr (cond_stmt), expand_omp_regimplify_p,
+ NULL, NULL)
+ || walk_tree (gimple_cond_rhs_ptr (cond_stmt), expand_omp_regimplify_p,
+ NULL, NULL))
+ {
+ gimple_stmt_iterator gsi = gsi_for_stmt (cond_stmt);
+ gimple_regimplify_operands (cond_stmt, &gsi);
+ }
+ return cond_stmt;
+}
+
/* Expand the OpenMP parallel or task directive starting at REGION. */
static void
@@ -1868,17 +1890,8 @@ expand_omp_for_init_counts (struct omp_for_data *fd, gimple_stmt_iterator *gsi,
n2 = fold_convert (itype, unshare_expr (fd->loops[i].n2));
n2 = force_gimple_operand_gsi (gsi, n2, true, NULL_TREE,
true, GSI_SAME_STMT);
- cond_stmt = gimple_build_cond (fd->loops[i].cond_code, n1, n2,
- NULL_TREE, NULL_TREE);
- gsi_insert_before (gsi, cond_stmt, GSI_SAME_STMT);
- if (walk_tree (gimple_cond_lhs_ptr (cond_stmt),
- expand_omp_regimplify_p, NULL, NULL)
- || walk_tree (gimple_cond_rhs_ptr (cond_stmt),
- expand_omp_regimplify_p, NULL, NULL))
- {
- *gsi = gsi_for_stmt (cond_stmt);
- gimple_regimplify_operands (cond_stmt, gsi);
- }
+ cond_stmt = expand_omp_build_cond (gsi, fd->loops[i].cond_code,
+ n1, n2);
e = split_block (entry_bb, cond_stmt);
basic_block &zero_iter_bb
= i < fd->collapse ? zero_iter1_bb : zero_iter2_bb;
@@ -2075,18 +2088,16 @@ expand_omp_for_init_counts (struct omp_for_data *fd, gimple_stmt_iterator *gsi,
n2e = force_gimple_operand_gsi (&gsi2, n2e, true, NULL_TREE,
true, GSI_SAME_STMT);
gcond *cond_stmt
- = gimple_build_cond (fd->loops[i].cond_code, n1, n2,
- NULL_TREE, NULL_TREE);
- gsi_insert_before (&gsi2, cond_stmt, GSI_SAME_STMT);
+ = expand_omp_build_cond (&gsi2, fd->loops[i].cond_code,
+ n1, n2);
e = split_block (bb1, cond_stmt);
e->flags = EDGE_TRUE_VALUE;
e->probability = profile_probability::likely ().guessed ();
basic_block bb2 = e->dest;
gsi2 = gsi_after_labels (bb2);
- cond_stmt = gimple_build_cond (fd->loops[i].cond_code, n1e, n2e,
- NULL_TREE, NULL_TREE);
- gsi_insert_before (&gsi2, cond_stmt, GSI_SAME_STMT);
+ cond_stmt = expand_omp_build_cond (&gsi2, fd->loops[i].cond_code,
+ n1e, n2e);
e = split_block (bb2, cond_stmt);
e->flags = EDGE_TRUE_VALUE;
e->probability = profile_probability::likely ().guessed ();
@@ -2137,9 +2148,8 @@ expand_omp_for_init_counts (struct omp_for_data *fd, gimple_stmt_iterator *gsi,
e->probability = profile_probability::unlikely ().guessed ();
gsi2 = gsi_after_labels (bb3);
- cond_stmt = gimple_build_cond (fd->loops[i].cond_code, n1e, n2e,
- NULL_TREE, NULL_TREE);
- gsi_insert_before (&gsi2, cond_stmt, GSI_SAME_STMT);
+ cond_stmt = expand_omp_build_cond (&gsi2, fd->loops[i].cond_code,
+ n1e, n2e);
e = split_block (bb3, cond_stmt);
e->flags = EDGE_TRUE_VALUE;
e->probability = profile_probability::likely ().guessed ();
@@ -2193,9 +2203,8 @@ expand_omp_for_init_counts (struct omp_for_data *fd, gimple_stmt_iterator *gsi,
true, GSI_SAME_STMT);
expand_omp_build_assign (&gsi2, j ? n2o : n1o, tem);
- cond_stmt = gimple_build_cond (fd->loops[i].cond_code, n1, n2,
- NULL_TREE, NULL_TREE);
- gsi_insert_before (&gsi2, cond_stmt, GSI_SAME_STMT);
+ cond_stmt = expand_omp_build_cond (&gsi2, fd->loops[i].cond_code,
+ n1, n2);
e = split_block (gsi_bb (gsi2), cond_stmt);
e->flags = j ? EDGE_TRUE_VALUE : EDGE_FALSE_VALUE;
e->probability = profile_probability::unlikely ().guessed ();
@@ -2298,9 +2307,8 @@ expand_omp_for_init_counts (struct omp_for_data *fd, gimple_stmt_iterator *gsi,
if (i == fd->last_nonrect)
{
gcond *cond_stmt
- = gimple_build_cond (fd->loops[i].cond_code, n1, n2,
- NULL_TREE, NULL_TREE);
- gsi_insert_before (&gsi2, cond_stmt, GSI_SAME_STMT);
+ = expand_omp_build_cond (&gsi2, fd->loops[i].cond_code,
+ n1, n2);
e = split_block (cur_bb, cond_stmt);
e->flags = EDGE_TRUE_VALUE;
ne = make_edge (cur_bb, next_bb, EDGE_FALSE_VALUE);
@@ -2354,10 +2362,7 @@ expand_omp_for_init_counts (struct omp_for_data *fd, gimple_stmt_iterator *gsi,
ne = split_block (e->dest, last_stmt (e->dest));
gsi2 = gsi_after_labels (ne->dest);
- gcond *cond_stmt
- = gimple_build_cond (fd->loops[i].cond_code, vs[i], n2,
- NULL_TREE, NULL_TREE);
- gsi_insert_before (&gsi2, cond_stmt, GSI_SAME_STMT);
+ expand_omp_build_cond (&gsi2, fd->loops[i].cond_code, vs[i], n2);
edge e3, e4;
if (next_bb == entry_bb)
{
@@ -2558,10 +2563,8 @@ expand_omp_for_init_vars (struct omp_for_data *fd, gimple_stmt_iterator *gsi,
tree first_inner_iterations = fd->first_inner_iterations;
tree factor = fd->factor;
gcond *cond_stmt
- = gimple_build_cond (NE_EXPR, factor,
- build_zero_cst (TREE_TYPE (factor)),
- NULL_TREE, NULL_TREE);
- gsi_insert_after (gsi, cond_stmt, GSI_CONTINUE_LINKING);
+ = expand_omp_build_cond (gsi, NE_EXPR, factor,
+ build_zero_cst (TREE_TYPE (factor)));
edge e = split_block (gsi_bb (*gsi), cond_stmt);
basic_block bb0 = e->src;
e->flags = EDGE_TRUE_VALUE;
@@ -2831,9 +2834,8 @@ expand_omp_for_init_vars (struct omp_for_data *fd, gimple_stmt_iterator *gsi,
if (j == fd->last_nonrect)
{
gcond *cond_stmt
- = gimple_build_cond (fd->loops[j].cond_code, n1, n2,
- NULL_TREE, NULL_TREE);
- gsi_insert_before (&gsi2, cond_stmt, GSI_SAME_STMT);
+ = expand_omp_build_cond (&gsi2, fd->loops[i].cond_code,
+ n1, n2);
e = split_block (cur_bb, cond_stmt);
e->flags = EDGE_TRUE_VALUE;
edge ne = make_edge (cur_bb, next_bb, EDGE_FALSE_VALUE);
@@ -4909,17 +4911,8 @@ expand_omp_for_static_nochunk (struct omp_region *region,
n2 = fold_convert (type, unshare_expr (fd->loop.n2));
n2 = force_gimple_operand_gsi (&gsi, n2, true, NULL_TREE,
true, GSI_SAME_STMT);
- gcond *cond_stmt = gimple_build_cond (fd->loop.cond_code, n1, n2,
- NULL_TREE, NULL_TREE);
- gsi_insert_before (&gsi, cond_stmt, GSI_SAME_STMT);
- if (walk_tree (gimple_cond_lhs_ptr (cond_stmt),
- expand_omp_regimplify_p, NULL, NULL)
- || walk_tree (gimple_cond_rhs_ptr (cond_stmt),
- expand_omp_regimplify_p, NULL, NULL))
- {
- gsi = gsi_for_stmt (cond_stmt);
- gimple_regimplify_operands (cond_stmt, &gsi);
- }
+ gcond *cond_stmt = expand_omp_build_cond (&gsi, fd->loop.cond_code,
+ n1, n2);
ep = split_block (entry_bb, cond_stmt);
ep->flags = EDGE_TRUE_VALUE;
entry_bb = ep->dest;
@@ -5713,17 +5706,8 @@ expand_omp_for_static_chunk (struct omp_region *region,
n2 = fold_convert (type, unshare_expr (fd->loop.n2));
n2 = force_gimple_operand_gsi (&gsi, n2, true, NULL_TREE,
true, GSI_SAME_STMT);
- gcond *cond_stmt = gimple_build_cond (fd->loop.cond_code, n1, n2,
- NULL_TREE, NULL_TREE);
- gsi_insert_before (&gsi, cond_stmt, GSI_SAME_STMT);
- if (walk_tree (gimple_cond_lhs_ptr (cond_stmt),
- expand_omp_regimplify_p, NULL, NULL)
- || walk_tree (gimple_cond_rhs_ptr (cond_stmt),
- expand_omp_regimplify_p, NULL, NULL))
- {
- gsi = gsi_for_stmt (cond_stmt);
- gimple_regimplify_operands (cond_stmt, &gsi);
- }
+ gcond *cond_stmt = expand_omp_build_cond (&gsi, fd->loop.cond_code,
+ n1, n2);
se = split_block (entry_bb, cond_stmt);
se->flags = EDGE_TRUE_VALUE;
entry_bb = se->dest;
diff --git a/gcc/testsuite/c-c++-common/gomp/loop-11.c b/gcc/testsuite/c-c++-common/gomp/loop-11.c
new file mode 100644
index 00000000000..5076e65b63d
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/loop-11.c
@@ -0,0 +1,5 @@
+/* PR tree-optimization/103208 */
+/* { dg-do compile } */
+/* { dg-additional-options "-O2 -fwrapv" } */
+
+#include "loop-8.c"
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-11-16 9:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-16 9:21 [gcc r12-5295] openmp: Regimplify operands of GIMPLE_COND in a few more places [PR103208] Jakub Jelinek
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).