Nathan noticed that the fortran FE wasn't lowering tiled loops in the same format as the C/C++ FEs. The canonical format of tiled loops going forward is that of omp/acc collapsed loops; tiled loops are lowered into a collection of tightly nested for loops. While making this change, I noticed that the fortran FE permitted acc loops to contain both tile and collapse clauses. This patch also makes that an error like it is in C and C++.
This patch has been applied to gomp-4_0-branch. Cesar
2016-10-04 Cesar Philippidis <ce...@codesourcery.com> gcc/fortran/ * openmp.c (resolve_omp_clauses): Error on directives containing both tile and collapse clauses. * trans-openmp.c (gfc_trans_omp_do): Lower tiled loops like collapsed loops. gcc/testsuite/ * gfortran.dg/goacc/tile-1.f90: Update test coverage. * gfortran.dg/goacc/tile-lowering.f95: Likewise. diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c index df489ba..e5eeb15 100644 --- a/gcc/fortran/openmp.c +++ b/gcc/fortran/openmp.c @@ -4092,6 +4092,8 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses, if (omp_clauses->wait_list) for (el = omp_clauses->wait_list; el; el = el->next) resolve_oacc_scalar_int_expr (el->expr, "WAIT"); + if (omp_clauses->collapse && omp_clauses->tile_list) + gfc_error ("Incompatible use of TILE and COLLAPSE at %L", &code->loc); } diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c index 2c28a31..e0e1c8b 100644 --- a/gcc/fortran/trans-openmp.c +++ b/gcc/fortran/trans-openmp.c @@ -3354,6 +3354,16 @@ gfc_trans_omp_do (gfc_code *code, gfc_exec_op op, stmtblock_t *pblock, dovar_init *di; unsigned ix; + /* Both collapsed and tiled loops are lowered the same way. In + OpenACC, those clauses are not compatible, so prioritize the tile + clause, if present. */ + if (clauses->tile_list) + { + collapse = 0; + for (gfc_expr_list *el = clauses->tile_list; el; el = el->next) + collapse++; + } + if (collapse <= 0) collapse = 1; diff --git a/gcc/testsuite/gfortran.dg/goacc/tile-1.f90 b/gcc/testsuite/gfortran.dg/goacc/tile-1.f90 index 967a7c3..17fd32c 100644 --- a/gcc/testsuite/gfortran.dg/goacc/tile-1.f90 +++ b/gcc/testsuite/gfortran.dg/goacc/tile-1.f90 @@ -79,6 +79,12 @@ subroutine parloop do j = 1, n end do end do + + !$acc parallel loop tile(2, 3) collapse (2) ! { dg-error "Incompatible use" } + do i = 1, n + do j = 1, n + end do + end do end subroutine parloop subroutine par @@ -153,6 +159,12 @@ subroutine par !$acc loop gang worker tile(*) do i = 1, n end do + + !$acc loop tile(2, 3) collapse (2) ! { dg-error "Incompatible use" } + do i = 1, n + do j = 1, n + end do + end do !$acc end parallel end subroutine par @@ -228,6 +240,12 @@ subroutine kern !$acc loop gang worker tile(*) do i = 1, n end do + + !$acc loop tile(2, 3) collapse (2) ! { dg-error "Incompatible use" } + do i = 1, n + do j = 1, n + end do + end do !$acc end kernels end subroutine kern @@ -312,4 +330,10 @@ subroutine kernsloop do j = 1, n end do end do + + !$acc kernels loop tile(2, 3) collapse (2) ! { dg-error "Incompatible use" } + do i = 1, n + do j = 1, n + end do + end do end subroutine kernsloop diff --git a/gcc/testsuite/gfortran.dg/goacc/tile-lowering.f95 b/gcc/testsuite/gfortran.dg/goacc/tile-lowering.f95 index b36cdc7..3774b38 100644 --- a/gcc/testsuite/gfortran.dg/goacc/tile-lowering.f95 +++ b/gcc/testsuite/gfortran.dg/goacc/tile-lowering.f95 @@ -82,4 +82,5 @@ end subroutine test ! { dg-final { scan-tree-dump-times "tile\\(0, 2, 3\\)" 1 "original" } } ! { dg-final { scan-tree-dump-times "tile\\(1, 0, 3\\)" 1 "original" } } ! { dg-final { scan-tree-dump-times "tile\\(1, 2, 0\\)" 1 "original" } } +! { dg-final { scan-tree-dump-times "for \\(" 22 "original" } }