Created attachment 41951 [details] Dump Fortran code like: tv(loc_idx(1:nhl,ip)) = xv%v(rmt_idx(1:nhl,ip))[xchg(ip)] leads to the generation of pseudo-code: atmp.33.dtype = 281; atmp.33.dim[0].stride = 1; atmp.33.dim[0].lbound = 0; atmp.33.dim[0].ubound = 1; atmp.33.data = (void * restrict) &A.34; atmp.33.offset = 0; { integer(kind=8) S.35; S.35 = 0; while (1) { if (S.35 > 1) goto L.26; { integer(kind=4) D.3704; D.3704 = (*(integer(kind=4)[0:] *) parm.32.data)[parm.32.dim[0].stride * NON_LVALUE_EXPR <S.35>]; (*(real(kind=4)[2] * restrict) atmp.33.data)[S.35] = (*D.3696)[(integer(kind=8)) D.3704 + D.3697]; } S.35 = S.35 + 1; } L.26:; } atmp.33.dtype = 281; caf_ref.36.type = 1; <snip> __asm__ __volatile__("":::"memory"); _gfortran_caf_get_by_ref (xv.v.token, ((*(integer(kind=4)[0:] * restrict) xchg.data)[xchg.offset + (integer(kind=8)) ip] - (integer(kind=4)) xv.v.dim[1].lbound) + 1, &atmp.33, &caf_ref.36, 4, 4, 0, 0, 0B); without copying back the result afterwards. In fact is the while(1) loop above unnecessary, because atmp.33 is write-only in this call. Example and dump attached.
Created attachment 41952 [details] Example producing the bug
Confirmed from 4.9 up to trunk (8.0). Related to pr83606.
Created attachment 43451 [details] Preliminary patch First shot on fixing the issue. At least for caf_get() it fixes the issue.
Candidate patch available at: https://gcc.gnu.org/ml/fortran/2018-04/msg00027.html
Author: vehre Date: Sat Apr 14 14:45:59 2018 New Revision: 259385 URL: https://gcc.gnu.org/viewcvs?rev=259385&root=gcc&view=rev Log: gcc/fortran/ChangeLog: 2018-04-14 Andre Vehreschild <vehre@gcc.gnu.org> PR fortran/81773 PR fortran/83606 * dependency.c (gfc_dep_resolver): Coarray indexes are to be ignored during dependency computation. They define no data dependency. * trans-array.c (conv_array_index_offset): The stride can not be set here, prevent fail. * trans-intrinsic.c (conv_caf_send): Add creation of temporary array for caf_get's result and copying to the array with vectorial indexing. gcc/testsuite/ChangeLog: 2018-04-14 Andre Vehreschild <vehre@gcc.gnu.org> PR fortran/81773 PR fortran/83606 * gfortran.dg/coarray/get_to_indexed_array_1.f90: New test. * gfortran.dg/coarray/get_to_indirect_array.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/coarray/get_to_indexed_array_1.f90 trunk/gcc/testsuite/gfortran.dg/coarray/get_to_indirect_array.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/dependency.c trunk/gcc/fortran/trans-array.c trunk/gcc/fortran/trans-intrinsic.c trunk/gcc/testsuite/ChangeLog
Fixed by r259385.
Author: vehre Date: Sat Apr 28 14:54:09 2018 New Revision: 259741 URL: https://gcc.gnu.org/viewcvs?rev=259741&root=gcc&view=rev Log: gcc/fortran/ChangeLog: 2018-04-28 Andre Vehreschild <vehre@gcc.gnu.org> PR fortran/81773 PR fortran/83606 Backport from trunk * dependency.c (gfc_dep_resolver): Coarray indexes are to be ignored during dependency computation. They define no data dependency. * trans-array.c (conv_array_index_offset): The stride can not be set here, prevent fail. * trans-intrinsic.c (conv_caf_send): Add creation of temporary array for caf_get's result and copying to the array with vectorial indexing. gcc/testsuite/ChangeLog: 2018-04-28 Andre Vehreschild <vehre@gcc.gnu.org> PR fortran/81773 PR fortran/83606 Backport from trunk * gfortran.dg/coarray/get_to_indexed_array_1.f90: New test. * gfortran.dg/coarray/get_to_indirect_array.f90: New test. Added: branches/gcc-6-branch/gcc/testsuite/gfortran.dg/coarray/get_to_indexed_array_1.f90 branches/gcc-6-branch/gcc/testsuite/gfortran.dg/coarray/get_to_indirect_array.f90 Modified: branches/gcc-6-branch/gcc/fortran/ChangeLog branches/gcc-6-branch/gcc/fortran/dependency.c branches/gcc-6-branch/gcc/fortran/trans-array.c branches/gcc-6-branch/gcc/fortran/trans-intrinsic.c branches/gcc-6-branch/gcc/testsuite/ChangeLog
Author: vehre Date: Sat Apr 28 14:54:20 2018 New Revision: 259742 URL: https://gcc.gnu.org/viewcvs?rev=259742&root=gcc&view=rev Log: gcc/fortran/ChangeLog: 2018-04-28 Andre Vehreschild <vehre@gcc.gnu.org> PR fortran/81773 PR fortran/83606 Backport from trunk * dependency.c (gfc_dep_resolver): Coarray indexes are to be ignored during dependency computation. They define no data dependency. * trans-array.c (conv_array_index_offset): The stride can not be set here, prevent fail. * trans-intrinsic.c (conv_caf_send): Add creation of temporary array for caf_get's result and copying to the array with vectorial indexing. gcc/testsuite/ChangeLog: 2018-04-28 Andre Vehreschild <vehre@gcc.gnu.org> PR fortran/81773 PR fortran/83606 Backport from trunk * gfortran.dg/coarray/get_to_indexed_array_1.f90: New test. * gfortran.dg/coarray/get_to_indirect_array.f90: New test. Added: branches/gcc-7-branch/gcc/testsuite/gfortran.dg/coarray/get_to_indexed_array_1.f90 branches/gcc-7-branch/gcc/testsuite/gfortran.dg/coarray/get_to_indirect_array.f90 Modified: branches/gcc-7-branch/gcc/fortran/ChangeLog branches/gcc-7-branch/gcc/fortran/dependency.c branches/gcc-7-branch/gcc/fortran/trans-array.c branches/gcc-7-branch/gcc/fortran/trans-intrinsic.c branches/gcc-7-branch/gcc/testsuite/ChangeLog
Author: vehre Date: Sun May 6 12:14:11 2018 New Revision: 259978 URL: https://gcc.gnu.org/viewcvs?rev=259978&root=gcc&view=rev Log: gcc/fortran/ChangeLog: 2018-04-28 Andre Vehreschild <vehre@gcc.gnu.org> PR fortran/81773 PR fortran/83606 Backport from trunk * dependency.c (gfc_dep_resolver): Coarray indexes are to be ignored during dependency computation. They define no data dependency. * trans-array.c (conv_array_index_offset): The stride can not be set here, prevent fail. * trans-intrinsic.c (conv_caf_send): Add creation of temporary array for caf_get's result and copying to the array with vectorial indexing. gcc/testsuite/ChangeLog: 2018-04-28 Andre Vehreschild <vehre@gcc.gnu.org> PR fortran/81773 PR fortran/83606 Backport from trunk * gfortran.dg/coarray/get_to_indexed_array_1.f90: New test. * gfortran.dg/coarray/get_to_indirect_array.f90: New test. Added: branches/gcc-6-branch/gcc/testsuite/gfortran.dg/coarray_dependency_1.f90 Modified: branches/gcc-6-branch/gcc/fortran/ChangeLog branches/gcc-6-branch/gcc/fortran/dependency.c branches/gcc-6-branch/gcc/fortran/trans-intrinsic.c branches/gcc-6-branch/gcc/testsuite/ChangeLog branches/gcc-6-branch/gcc/testsuite/gfortran.dg/coarray_lib_comm_1.f90
Author: vehre Revision: 259978 Modified property: svn:log Modified: svn:log at Sun May 6 12:20:52 2018 ------------------------------------------------------------------------------ --- svn:log (original) +++ svn:log Sun May 6 12:20:52 2018 @@ -1,25 +1,21 @@ gcc/fortran/ChangeLog: -2018-04-28 Andre Vehreschild <vehre@gcc.gnu.org> +2018-05-06 Andre Vehreschild <vehre@gcc.gnu.org> - PR fortran/81773 - PR fortran/83606 - Backport from trunk - * dependency.c (gfc_dep_resolver): Coarray indexes are to be ignored - during dependency computation. They define no data dependency. - * trans-array.c (conv_array_index_offset): The stride can not be set - here, prevent fail. - * trans-intrinsic.c (conv_caf_send): Add creation of temporary array - for caf_get's result and copying to the array with vectorial - indexing. + PR fortran/85507 + Backport from trunk. + * dependency.c (gfc_dep_resolver): Revert looking at coarray dimension + introduced by r259385. + * trans-intrinsic.c (conv_caf_send): Always report a dependency for + same variables in coarray assignments. gcc/testsuite/ChangeLog: -2018-04-28 Andre Vehreschild <vehre@gcc.gnu.org> +2018-05-06 Andre Vehreschild <vehre@gcc.gnu.org> - PR fortran/81773 - PR fortran/83606 - Backport from trunk - * gfortran.dg/coarray/get_to_indexed_array_1.f90: New test. - * gfortran.dg/coarray/get_to_indirect_array.f90: New test. + PR fortran/85507 + Backport from trunk. + * gfortran.dg/coarray_dependency_1.f90: New test. + * gfortran.dg/coarray_lib_comm_1.f90: Fix counting caf-expressions. +