[committed] openmp: Use more efficient logical -> actual computation even if # iterations is computed at runtime
Jakub Jelinek
jakub@redhat.com
Wed Aug 5 08:58:18 GMT 2020
Hi!
For triangular loops use more efficient logical iteration number
to actual iterator values computation even for non-rectangular loops
where number of loop iterations could not be computed at compile time.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.
2020-08-05 Jakub Jelinek <jakub@redhat.com>
* omp-expand.c (expand_omp_for_init_counts): Remember
first_inner_iterations, factor and n1o from the number of iterations
computation in *fd.
(expand_omp_for_init_vars): Use more efficient logical iteration number
to actual iterator values computation even for non-rectangular loops
where number of loop iterations could not be computed at compile time.
--- gcc/omp-expand.c.jj 2020-08-04 10:53:03.114637202 +0200
+++ gcc/omp-expand.c 2020-08-04 13:05:18.522759444 +0200
@@ -2181,6 +2181,13 @@ expand_omp_for_init_counts (struct omp_f
set_immediate_dominator (CDI_DOMINATORS, bb3, bb1);
set_immediate_dominator (CDI_DOMINATORS, bb5, bb2);
set_immediate_dominator (CDI_DOMINATORS, entry_bb, bb1);
+
+ if (fd->first_nonrect + 1 == fd->last_nonrect)
+ {
+ fd->first_inner_iterations = first_inner_iterations;
+ fd->factor = factor;
+ fd->adjn1 = n1o;
+ }
}
else
{
@@ -2469,8 +2476,11 @@ expand_omp_for_init_vars (struct omp_for
build_zero_cst (type), true);
basic_block bb_triang = NULL, bb_triang_dom = NULL;
if (fd->first_nonrect + 1 == fd->last_nonrect
- /* For now. */
- && TREE_CODE (fd->loop.n2) == INTEGER_CST
+ && (TREE_CODE (fd->loop.n2) == INTEGER_CST
+ || (fd->first_inner_iterations
+ /* For now. Later add clauses to propagate the
+ values. */
+ && !gimple_omp_for_combined_into_p (fd->for_stmt)))
&& (optab_handler (sqrt_optab, TYPE_MODE (double_type_node))
!= CODE_FOR_nothing))
{
@@ -2567,14 +2577,19 @@ expand_omp_for_init_vars (struct omp_for
build_one_cst (ulltype));
t = fold_build2 (MULT_EXPR, ulltype, c, t);
t = fold_build2 (RSHIFT_EXPR, ulltype, t, integer_one_node);
- t = fold_build2 (MULT_EXPR, ulltype, fd->factor, t);
- tree t2 = fold_build2 (MULT_EXPR, ulltype, c,
- fd->first_inner_iterations);
+ t = fold_build2 (MULT_EXPR, ulltype,
+ fold_convert (ulltype, fd->factor), t);
+ tree t2
+ = fold_build2 (MULT_EXPR, ulltype, c,
+ fold_convert (ulltype,
+ fd->first_inner_iterations));
t = fold_build2 (PLUS_EXPR, ulltype, t, t2);
expand_omp_build_assign (gsi, d, t, true);
- t = fold_build2 (MULT_EXPR, ulltype, fd->factor, c);
+ t = fold_build2 (MULT_EXPR, ulltype,
+ fold_convert (ulltype, fd->factor), c);
t = fold_build2 (PLUS_EXPR, ulltype,
- t, fd->first_inner_iterations);
+ t, fold_convert (ulltype,
+ fd->first_inner_iterations));
t2 = force_gimple_operand_gsi (gsi, t, true, NULL_TREE, false,
GSI_CONTINUE_LINKING);
cond_stmt = gimple_build_cond (GE_EXPR, stopvalull, d,
Jakub
More information about the Gcc-patches
mailing list