aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
diff options
context:
space:
mode:
authorTobias Burnus <tobias@codesourcery.com>2023-07-19 10:18:49 +0200
committerTobias Burnus <tobias@codesourcery.com>2023-07-19 10:18:49 +0200
commit85da0b40538fb0d17d89de1e7905984668e3dfef (patch)
tree2661f18264cfb9b9310d03429de8deb8cd9574b5 /gcc/fortran
parentc283c4774d1cbfd12c2a15b51b18347463694ad0 (diff)
downloadgcc-85da0b40538fb0d17d89de1e7905984668e3dfef.zip
gcc-85da0b40538fb0d17d89de1e7905984668e3dfef.tar.gz
gcc-85da0b40538fb0d17d89de1e7905984668e3dfef.tar.bz2
OpenMP/Fortran: Non-rectangular loops with constant steps other than 1 or -1 [PR107424]
Before this commit, gfortran produced with OpenMP for 'do i = 1,10,2' the code for (count.0 = 0; count.0 < 5; count.0 = count.0 + 1) i = count.0 * 2 + 1; While such an inner loop can be collapsed, a non-rectangular could not. With this commit and for all constant loop steps, a simple loop such as 'for (i = 1; i <= 10; i = i + 2)' is created. (Before only for the constant steps of 1 and -1.) The constant step permits to know the direction (increasing/decreasing) that is required for the loop condition. The new code is only valid if one assumes no overflow of the loop variable. However, the Fortran standard can be read that this must be ensured by the user. Namely, the Fortran standard requires (F2023, 10.1.5.2.4): "The execution of any numeric operation whose result is not defined by the arithmetic used by the processor is prohibited." And, for DO loops, F2023's "11.1.7.4.3 The execution cycle" has the following: The number of loop iterations handled by an iteration count, which would permit code like 'do i = huge(i)-5, huge(i),4'. However, in step (3), this count is not only decremented by one but also: "... The DO variable, if any, is incremented by the value of the incrementation parameter m3." And for the example above, 'i' would be 'huge(i)+3' in the last execution cycle, which exceeds the largest model number and should render the example as invalid. PR fortran/107424 gcc/fortran/ChangeLog: * trans-openmp.cc (gfc_nonrect_loop_expr): Accept all constant loop steps. (gfc_trans_omp_do): Likewise; use sign to determine loop direction. libgomp/ChangeLog: * libgomp.texi (Impl. Status 5.0): Add link to new PR110735. * testsuite/libgomp.fortran/non-rectangular-loop-1.f90: Enable commented tests. * testsuite/libgomp.fortran/non-rectangular-loop-1a.f90: Remove test file; tests are in non-rectangular-loop-1.f90. * testsuite/libgomp.fortran/non-rectangular-loop-5.f90: Change testcase to use a non-constant step to retain the 'sorry' test. * testsuite/libgomp.fortran/non-rectangular-loop-6.f90: New test. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/linear-2.f90: Update dump to remove the additional count variable.
Diffstat (limited to 'gcc/fortran')
-rw-r--r--gcc/fortran/trans-openmp.cc18
1 files changed, 8 insertions, 10 deletions
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index c88ee3c..cf741ce 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -5374,10 +5374,10 @@ gfc_nonrect_loop_expr (stmtblock_t *pblock, gfc_se *sep, int loop_n,
if (!simple)
{
- /* FIXME: Handle non-unit iter steps, cf. PR fortran/107424. */
+ /* FIXME: Handle non-const iter steps, cf. PR fortran/110735. */
sorry_at (gfc_get_location (&curr_loop_var->where),
- "non-rectangular loop nest with step other than constant 1 "
- "or -1 for %qs", curr_loop_var->symtree->n.sym->name);
+ "non-rectangular loop nest with non-constant step for %qs",
+ curr_loop_var->symtree->n.sym->name);
return false;
}
@@ -5394,10 +5394,10 @@ gfc_nonrect_loop_expr (stmtblock_t *pblock, gfc_se *sep, int loop_n,
}
else
{
- /* FIXME: Handle non-unit iter steps, cf. PR fortran/107424. */
+ /* FIXME: Handle non-const iter steps, cf. PR fortran/110735. */
sorry_at (gfc_get_location (&code->loc),
- "non-rectangular loop nest with step other than constant "
- "1 or -1 for %qs", var->name);
+ "non-rectangular loop nest with non-constant step "
+ "for %qs", var->name);
inform (gfc_get_location (&expr->where), "Used here");
return false;
}
@@ -5578,10 +5578,8 @@ gfc_trans_omp_do (gfc_code *code, gfc_exec_op op, stmtblock_t *pblock,
gfc_add_block_to_block (pblock, &se.pre);
step = gfc_evaluate_now (se.expr, pblock);
- if (integer_onep (step))
- simple = 1;
- else if (tree_int_cst_equal (step, integer_minus_one_node))
- simple = -1;
+ if (TREE_CODE (step) == INTEGER_CST)
+ simple = tree_int_cst_sgn (step);
gfc_init_se (&se, NULL);
if (!clauses->non_rectangular