diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-10-13 09:30:47 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-10-13 09:30:47 +0200 |
commit | 14707c896a207606f13886d3b3251e8db1f3c9c0 (patch) | |
tree | ae58e04fa9797de1ec9a35349d0df94a776554d3 /gcc/omp-low.c | |
parent | 56cb815ba22dd2ec00fee7a38f0862bc21d1c2a9 (diff) | |
download | gcc-14707c896a207606f13886d3b3251e8db1f3c9c0.zip gcc-14707c896a207606f13886d3b3251e8db1f3c9c0.tar.gz gcc-14707c896a207606f13886d3b3251e8db1f3c9c0.tar.bz2 |
openmp: Improve composite triangular loop lowering and expansion
This propagates needed values from the point where number of iterations
is calculated on composite loops to the places where that information
is needed to use the more efficient square root discovery to compute
the starting iterator values from the logical iteration number.
2020-10-13 Jakub Jelinek <jakub@redhat.com>
* omp-low.c (add_taskreg_looptemp_clauses): For triangular loops
with non-constant number of iterations add another 4 _looptemp_
clauses before the (optional) one for lastprivate.
(lower_omp_for_lastprivate): Skip those clauses when looking for
the lastprivate clause.
(lower_omp_for): For triangular loops with non-constant number of
iterations add another 4 _looptemp_ clauses.
* omp-expand.c (expand_omp_for_init_counts): For triangular loops
with non-constant number of iterations set counts[0],
fd->first_inner_iterations, fd->factor and fd->adjn1 from the newly
added _looptemp_ clauses.
(expand_omp_for_init_vars): Initialize the newly added _looptemp_
clauses.
(find_lastprivate_looptemp): New function.
(expand_omp_for_static_nochunk, expand_omp_for_static_chunk,
expand_omp_taskloop_for_outer): Use it instead of manually skipping
_looptemp_ clauses.
Diffstat (limited to 'gcc/omp-low.c')
-rw-r--r-- | gcc/omp-low.c | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/gcc/omp-low.c b/gcc/omp-low.c index b3e2468..6d0aa8d 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -1919,12 +1919,38 @@ add_taskreg_looptemp_clauses (enum gf_mask msk, gimple *stmt, GIMPLE_OMP_FOR, add one more temporaries for the total number of iterations (product of count1 ... countN-1). */ if (omp_find_clause (gimple_omp_for_clauses (for_stmt), - OMP_CLAUSE_LASTPRIVATE)) - count++; - else if (msk == GF_OMP_FOR_KIND_FOR - && omp_find_clause (gimple_omp_parallel_clauses (stmt), - OMP_CLAUSE_LASTPRIVATE)) - count++; + OMP_CLAUSE_LASTPRIVATE) + || (msk == GF_OMP_FOR_KIND_FOR + && omp_find_clause (gimple_omp_parallel_clauses (stmt), + OMP_CLAUSE_LASTPRIVATE))) + { + tree temp = create_tmp_var (type); + tree c = build_omp_clause (UNKNOWN_LOCATION, + OMP_CLAUSE__LOOPTEMP_); + insert_decl_map (&outer_ctx->cb, temp, temp); + OMP_CLAUSE_DECL (c) = temp; + OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt); + gimple_omp_taskreg_set_clauses (stmt, c); + } + if (fd.non_rect + && fd.last_nonrect == fd.first_nonrect + 1) + if (tree v = gimple_omp_for_index (for_stmt, fd.last_nonrect)) + if (!TYPE_UNSIGNED (TREE_TYPE (v))) + { + v = gimple_omp_for_index (for_stmt, fd.first_nonrect); + tree type2 = TREE_TYPE (v); + count++; + for (i = 0; i < 3; i++) + { + tree temp = create_tmp_var (type2); + tree c = build_omp_clause (UNKNOWN_LOCATION, + OMP_CLAUSE__LOOPTEMP_); + insert_decl_map (&outer_ctx->cb, temp, temp); + OMP_CLAUSE_DECL (c) = temp; + OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt); + gimple_omp_taskreg_set_clauses (stmt, c); + } + } } for (i = 0; i < count; i++) { @@ -9530,7 +9556,13 @@ lower_omp_for_lastprivate (struct omp_for_data *fd, gimple_seq *body_p, tree innerc = omp_find_clause (taskreg_clauses, OMP_CLAUSE__LOOPTEMP_); gcc_assert (innerc); - for (i = 0; i < fd->collapse; i++) + int count = fd->collapse; + if (fd->non_rect + && fd->last_nonrect == fd->first_nonrect + 1) + if (tree v = gimple_omp_for_index (fd->for_stmt, fd->last_nonrect)) + if (!TYPE_UNSIGNED (TREE_TYPE (v))) + count += 4; + for (i = 0; i < count; i++) { innerc = omp_find_clause (OMP_CLAUSE_CHAIN (innerc), OMP_CLAUSE__LOOPTEMP_); @@ -10453,12 +10485,26 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx) if (fd.collapse > 1 && TREE_CODE (fd.loop.n2) != INTEGER_CST) count += fd.collapse - 1; + size_t count2 = 0; + tree type2 = NULL_TREE; bool taskreg_for = (gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_FOR || gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_TASKLOOP); tree outerc = NULL, *pc = gimple_omp_for_clauses_ptr (stmt); tree simtc = NULL; tree clauses = *pc; + if (fd.collapse > 1 + && fd.non_rect + && fd.last_nonrect == fd.first_nonrect + 1 + && TREE_CODE (fd.loop.n2) != INTEGER_CST) + if (tree v = gimple_omp_for_index (stmt, fd.last_nonrect)) + if (!TYPE_UNSIGNED (TREE_TYPE (v))) + { + v = gimple_omp_for_index (stmt, fd.first_nonrect); + type2 = TREE_TYPE (v); + count++; + count2 = 3; + } if (taskreg_for) outerc = omp_find_clause (gimple_omp_taskreg_clauses (ctx->outer->stmt), @@ -10466,7 +10512,7 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx) if (ctx->simt_stmt) simtc = omp_find_clause (gimple_omp_for_clauses (ctx->simt_stmt), OMP_CLAUSE__LOOPTEMP_); - for (i = 0; i < count; i++) + for (i = 0; i < count + count2; i++) { tree temp; if (taskreg_for) @@ -10485,7 +10531,7 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx) if (ctx->simt_stmt) temp = OMP_CLAUSE_DECL (simtc); else - temp = create_tmp_var (type); + temp = create_tmp_var (i >= count ? type2 : type); insert_decl_map (&ctx->outer->cb, temp, temp); } *pc = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__LOOPTEMP_); |