[Fortran, Patch, PR81773, PR83606, coarray, v1] Fix coarray get to array with vector indexing
Hi all, attached patch fixes (to my knowledge) the two PRs 81773 and 83606 where the result of a coarray get() operation is assigned to an array using a vector as index. It took me quite long to get it right, because I had to use the scalarizer which I haven't use directly before. So reviewers with expertise on using the scalarizer are especially welcome. Bootstrapped and regtested on x86_64-linux/f27. Ok for trunk? Backports? Regards, Andre -- Andre Vehreschild * Email: vehre ad gmx dot de gcc/fortran/ChangeLog: 2018-04-08 Andre Vehreschild 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-08 Andre Vehreschild 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. diff --git a/gcc/fortran/dependency.c b/gcc/fortran/dependency.c index a0bbd584947..3e14ddc25d8 100644 --- a/gcc/fortran/dependency.c +++ b/gcc/fortran/dependency.c @@ -2238,8 +2238,9 @@ gfc_dep_resolver (gfc_ref *lref, gfc_ref *rref, gfc_reverse *reverse) break; /* Exactly matching and forward overlapping ranges don't cause a - dependency. */ - if (fin_dep < GFC_DEP_BACKWARD) + dependency, when they are not part of a coarray ref. */ + if (fin_dep < GFC_DEP_BACKWARD + && lref->u.ar.codimen == 0 && rref->u.ar.codimen == 0) return 0; /* Keep checking. We only have a dependency if diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index bd731689031..b68e77d5281 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -3215,7 +3215,7 @@ conv_array_index_offset (gfc_se * se, gfc_ss * ss, int dim, int i, } /* Multiply by the stride. */ - if (!integer_onep (stride)) + if (stride != NULL && !integer_onep (stride)) index = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, index, stride); diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index a45aec708fb..00edd447bb2 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -1907,34 +1907,124 @@ conv_caf_send (gfc_code *code) { } else { - /* If has_vector, pass descriptor for whole array and the - vector bounds separately. */ - gfc_array_ref *ar, ar2; - bool has_vector = false; + bool has_vector = gfc_has_vector_subscript (lhs_expr); - if (gfc_is_coindexed (lhs_expr) && gfc_has_vector_subscript (lhs_expr)) + if (gfc_is_coindexed (lhs_expr) || !has_vector) { - has_vector = true; - ar = gfc_find_array_ref (lhs_expr); - ar2 = *ar; - memset (ar, '\0', sizeof (*ar)); - ar->as = ar2.as; - ar->type = AR_FULL; + /* If has_vector, pass descriptor for whole array and the + vector bounds separately. */ + gfc_array_ref *ar, ar2; + bool has_tmp_lhs_array = false; + if (has_vector) + { + has_tmp_lhs_array = true; + ar = gfc_find_array_ref (lhs_expr); + ar2 = *ar; + memset (ar, '\0', sizeof (*ar)); + ar->as = ar2.as; + ar->type = AR_FULL; + } + lhs_se.want_pointer = 1; + gfc_conv_expr_descriptor (&lhs_se, lhs_expr); + /* Using gfc_conv_expr_descriptor, we only get the descriptor, but + that has the wrong type if component references are done. */ + lhs_type = gfc_typenode_for_spec (&lhs_expr->ts); + tmp = build_fold_indirect_ref_loc (input_location, lhs_se.expr); + gfc_add_modify (&lhs_se.pre, gfc_conv_descriptor_dtype (tmp), + gfc_get_dtype_rank_type (has_vector ? ar2.dimen + : lhs_expr->rank, + lhs_type)); + if (has_tmp_lhs_array) + { + vec = conv_caf_vector_subscript (&block, lhs_se.expr, &ar2); + *ar = ar2; + } } - lhs_se.want_pointer = 1; - gfc_conv_expr_descriptor (&lhs_se, lhs_expr); - /* Using gfc_conv_expr_descriptor, we only get the descriptor, but that - has the wrong type if component references are done. */ - lhs_type = gfc_typenode_for_spec (&lhs_expr->ts); - tmp = build_fold_indirect_ref_loc (input_location, lhs_se.expr); - gfc_add_modify (&lhs_se.pre, gfc_conv_descriptor_dtype (tmp), - gfc_get_dtype_rank_type (has_vector ? ar2.dimen - : lhs_expr->rank, - lhs_type)); - if (has_vector) + else { - vec = conv_caf_vector_subscript (&block, lhs_se.expr, &ar2); - *ar = ar2; + /* Special casing for arr1 ([...]) = arr2[...], i.e. caf_get to + index
Re: [Ping, Fortran, Patch, PR81773, PR83606, coarray, v1] Fix coarray get to array with vector indexing
Ping On Sun, 8 Apr 2018 14:25:50 +0200 Andre Vehreschild wrote: > Hi all, > > attached patch fixes (to my knowledge) the two PRs 81773 and 83606 where the > result of a coarray get() operation is assigned to an array using a vector as > index. It took me quite long to get it right, because I had to use the > scalarizer which I haven't use directly before. So reviewers with expertise on > using the scalarizer are especially welcome. > > Bootstrapped and regtested on x86_64-linux/f27. > > Ok for trunk? Backports? > > Regards, > Andre -- Andre Vehreschild * Email: vehre ad gmx dot de gcc/fortran/ChangeLog: 2018-04-08 Andre Vehreschild 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-08 Andre Vehreschild 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. diff --git a/gcc/fortran/dependency.c b/gcc/fortran/dependency.c index a0bbd584947..3e14ddc25d8 100644 --- a/gcc/fortran/dependency.c +++ b/gcc/fortran/dependency.c @@ -2238,8 +2238,9 @@ gfc_dep_resolver (gfc_ref *lref, gfc_ref *rref, gfc_reverse *reverse) break; /* Exactly matching and forward overlapping ranges don't cause a - dependency. */ - if (fin_dep < GFC_DEP_BACKWARD) + dependency, when they are not part of a coarray ref. */ + if (fin_dep < GFC_DEP_BACKWARD + && lref->u.ar.codimen == 0 && rref->u.ar.codimen == 0) return 0; /* Keep checking. We only have a dependency if diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index bd731689031..b68e77d5281 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -3215,7 +3215,7 @@ conv_array_index_offset (gfc_se * se, gfc_ss * ss, int dim, int i, } /* Multiply by the stride. */ - if (!integer_onep (stride)) + if (stride != NULL && !integer_onep (stride)) index = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, index, stride); diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index a45aec708fb..00edd447bb2 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -1907,34 +1907,124 @@ conv_caf_send (gfc_code *code) { } else { - /* If has_vector, pass descriptor for whole array and the - vector bounds separately. */ - gfc_array_ref *ar, ar2; - bool has_vector = false; + bool has_vector = gfc_has_vector_subscript (lhs_expr); - if (gfc_is_coindexed (lhs_expr) && gfc_has_vector_subscript (lhs_expr)) + if (gfc_is_coindexed (lhs_expr) || !has_vector) { - has_vector = true; - ar = gfc_find_array_ref (lhs_expr); - ar2 = *ar; - memset (ar, '\0', sizeof (*ar)); - ar->as = ar2.as; - ar->type = AR_FULL; + /* If has_vector, pass descriptor for whole array and the + vector bounds separately. */ + gfc_array_ref *ar, ar2; + bool has_tmp_lhs_array = false; + if (has_vector) + { + has_tmp_lhs_array = true; + ar = gfc_find_array_ref (lhs_expr); + ar2 = *ar; + memset (ar, '\0', sizeof (*ar)); + ar->as = ar2.as; + ar->type = AR_FULL; + } + lhs_se.want_pointer = 1; + gfc_conv_expr_descriptor (&lhs_se, lhs_expr); + /* Using gfc_conv_expr_descriptor, we only get the descriptor, but + that has the wrong type if component references are done. */ + lhs_type = gfc_typenode_for_spec (&lhs_expr->ts); + tmp = build_fold_indirect_ref_loc (input_location, lhs_se.expr); + gfc_add_modify (&lhs_se.pre, gfc_conv_descriptor_dtype (tmp), + gfc_get_dtype_rank_type (has_vector ? ar2.dimen + : lhs_expr->rank, + lhs_type)); + if (has_tmp_lhs_array) + { + vec = conv_caf_vector_subscript (&block, lhs_se.expr, &ar2); + *ar = ar2; + } } - lhs_se.want_pointer = 1; - gfc_conv_expr_descriptor (&lhs_se, lhs_expr); - /* Using gfc_conv_expr_descriptor, we only get the descriptor, but that - has the wrong type if component references are done. */ - lhs_type = gfc_typenode_for_spec (&lhs_expr->ts); - tmp = build_fold_indirect_ref_loc (input_location, lhs_se.expr); - gfc_add_modify (&lhs_se.pre, gfc_conv_descriptor_dtype (tmp), - gfc_get_dtype_rank_type (has_vector ? ar2.dimen - : lhs_expr->rank, - lhs_type)); - if (has_vector) + else { - vec = conv_caf_vector_subscript (&block, lhs_se.expr, &ar2);
Re: [Ping, Fortran, Patch, PR81773, PR83606, coarray, v1] Fix coarray get to array with vector indexing
Hi Andre, This is OK for trunk. Thanks for the patch Paul On 13 April 2018 at 08:34, Andre Vehreschild wrote: > Ping > > On Sun, 8 Apr 2018 14:25:50 +0200 > Andre Vehreschild wrote: > >> Hi all, >> >> attached patch fixes (to my knowledge) the two PRs 81773 and 83606 where the >> result of a coarray get() operation is assigned to an array using a vector as >> index. It took me quite long to get it right, because I had to use the >> scalarizer which I haven't use directly before. So reviewers with expertise >> on >> using the scalarizer are especially welcome. >> >> Bootstrapped and regtested on x86_64-linux/f27. >> >> Ok for trunk? Backports? >> >> Regards, >> Andre > > > -- > Andre Vehreschild * Email: vehre ad gmx dot de -- "If you can't explain it simply, you don't understand it well enough" - Albert Einstein
Re: [Ping, Fortran, Patch, PR81773, PR83606, coarray, v1] Fix coarray get to array with vector indexing
Hi Paul, thank you for the review. Committed as r259385. Regards, Andre On Sat, 14 Apr 2018 11:53:44 +0100 Paul Richard Thomas wrote: > Hi Andre, > > This is OK for trunk. > > Thanks for the patch > > Paul > > > On 13 April 2018 at 08:34, Andre Vehreschild wrote: > > Ping > > > > On Sun, 8 Apr 2018 14:25:50 +0200 > > Andre Vehreschild wrote: > > > >> Hi all, > >> > >> attached patch fixes (to my knowledge) the two PRs 81773 and 83606 where > >> the result of a coarray get() operation is assigned to an array using a > >> vector as index. It took me quite long to get it right, because I had to > >> use the scalarizer which I haven't use directly before. So reviewers with > >> expertise on using the scalarizer are especially welcome. > >> > >> Bootstrapped and regtested on x86_64-linux/f27. > >> > >> Ok for trunk? Backports? > >> > >> Regards, > >> Andre > > > > > > -- > > Andre Vehreschild * Email: vehre ad gmx dot de > > > -- Andre Vehreschild * Email: vehre ad gmx dot de Index: gcc/fortran/ChangeLog === --- gcc/fortran/ChangeLog (Revision 259384) +++ gcc/fortran/ChangeLog (Arbeitskopie) @@ -1,3 +1,15 @@ +2018-04-14 Andre Vehreschild + + 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. + 2018-04-14 Thomas Koenig PR fortran/85387 Index: gcc/fortran/dependency.c === --- gcc/fortran/dependency.c (Revision 259384) +++ gcc/fortran/dependency.c (Arbeitskopie) @@ -2238,8 +2238,9 @@ break; /* Exactly matching and forward overlapping ranges don't cause a - dependency. */ - if (fin_dep < GFC_DEP_BACKWARD) + dependency, when they are not part of a coarray ref. */ + if (fin_dep < GFC_DEP_BACKWARD + && lref->u.ar.codimen == 0 && rref->u.ar.codimen == 0) return 0; /* Keep checking. We only have a dependency if Index: gcc/fortran/trans-array.c === --- gcc/fortran/trans-array.c (Revision 259384) +++ gcc/fortran/trans-array.c (Arbeitskopie) @@ -3215,7 +3215,7 @@ } /* Multiply by the stride. */ - if (!integer_onep (stride)) + if (stride != NULL && !integer_onep (stride)) index = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, index, stride); Index: gcc/fortran/trans-intrinsic.c === --- gcc/fortran/trans-intrinsic.c (Revision 259384) +++ gcc/fortran/trans-intrinsic.c (Arbeitskopie) @@ -1907,34 +1907,124 @@ } else { - /* If has_vector, pass descriptor for whole array and the - vector bounds separately. */ - gfc_array_ref *ar, ar2; - bool has_vector = false; + bool has_vector = gfc_has_vector_subscript (lhs_expr); - if (gfc_is_coindexed (lhs_expr) && gfc_has_vector_subscript (lhs_expr)) + if (gfc_is_coindexed (lhs_expr) || !has_vector) { - has_vector = true; - ar = gfc_find_array_ref (lhs_expr); - ar2 = *ar; - memset (ar, '\0', sizeof (*ar)); - ar->as = ar2.as; - ar->type = AR_FULL; + /* If has_vector, pass descriptor for whole array and the + vector bounds separately. */ + gfc_array_ref *ar, ar2; + bool has_tmp_lhs_array = false; + if (has_vector) + { + has_tmp_lhs_array = true; + ar = gfc_find_array_ref (lhs_expr); + ar2 = *ar; + memset (ar, '\0', sizeof (*ar)); + ar->as = ar2.as; + ar->type = AR_FULL; + } + lhs_se.want_pointer = 1; + gfc_conv_expr_descriptor (&lhs_se, lhs_expr); + /* Using gfc_conv_expr_descriptor, we only get the descriptor, but + that has the wrong type if component references are done. */ + lhs_type = gfc_typenode_for_spec (&lhs_expr->ts); + tmp = build_fold_indirect_ref_loc (input_location, lhs_se.expr); + gfc_add_modify (&lhs_se.pre, gfc_conv_descriptor_dtype (tmp), + gfc_get_dtype_rank_type (has_vector ? ar2.dimen + : lhs_expr->rank, + lhs_type)); + if (has_tmp_lhs_array) + { + vec = conv_caf_vector_subscript (&block, lhs_se.expr, &ar2); + *ar = ar2; + } } - lhs_se.want_pointer = 1; - gfc_conv_expr_descriptor (&lhs_se, lhs_expr); - /* Using gfc_conv_expr_descriptor, we only get the descriptor, but that - has the wrong type if component references are done. */ - lhs_type = gfc_typenode_for_spec (&lhs_expr->ts); - tmp = build_fold_indirect_ref_loc (input_location, lhs_se.expr); - gfc_add_modify (&lhs_se.pre, gfc_co
Re: [Ping, Fortran, Patch, PR81773, PR83606, coarray, v1] Fix coarray get to array with vector indexing
Hi all, because pr81773 is a 6-/7-/8-regression I have backported it to gcc-6 as r259741 and gcc-7 as r259742. Regards, Andre On Sat, 14 Apr 2018 16:46:53 +0200 Andre Vehreschild wrote: > Hi Paul, > > thank you for the review. Committed as r259385. > > Regards, > Andre > > On Sat, 14 Apr 2018 11:53:44 +0100 > Paul Richard Thomas wrote: > > > Hi Andre, > > > > This is OK for trunk. > > > > Thanks for the patch > > > > Paul > > > > > > On 13 April 2018 at 08:34, Andre Vehreschild wrote: > > > Ping > > > > > > On Sun, 8 Apr 2018 14:25:50 +0200 > > > Andre Vehreschild wrote: > > > > > >> Hi all, > > >> > > >> attached patch fixes (to my knowledge) the two PRs 81773 and 83606 where > > >> the result of a coarray get() operation is assigned to an array using a > > >> vector as index. It took me quite long to get it right, because I had to > > >> use the scalarizer which I haven't use directly before. So reviewers with > > >> expertise on using the scalarizer are especially welcome. > > >> > > >> Bootstrapped and regtested on x86_64-linux/f27. > > >> > > >> Ok for trunk? Backports? > > >> > > >> Regards, > > >> Andre > > > > > > > > > -- > > > Andre Vehreschild * Email: vehre ad gmx dot de > > > > > > > > -- Andre Vehreschild * Email: vehre ad gmx dot de Index: gcc/fortran/ChangeLog === --- gcc/fortran/ChangeLog (Revision 259739) +++ gcc/fortran/ChangeLog (Arbeitskopie) @@ -1,3 +1,16 @@ +2018-04-28 Andre Vehreschild + + 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. + 2018-04-24 Steven G. Kargl PR fortran/85520 Index: gcc/fortran/dependency.c === --- gcc/fortran/dependency.c (Revision 259739) +++ gcc/fortran/dependency.c (Arbeitskopie) @@ -2239,8 +2239,9 @@ break; /* Exactly matching and forward overlapping ranges don't cause a - dependency. */ - if (fin_dep < GFC_DEP_BACKWARD) + dependency, when they are not part of a coarray ref. */ + if (fin_dep < GFC_DEP_BACKWARD + && lref->u.ar.codimen == 0 && rref->u.ar.codimen == 0) return 0; /* Keep checking. We only have a dependency if Index: gcc/fortran/trans-array.c === --- gcc/fortran/trans-array.c (Revision 259739) +++ gcc/fortran/trans-array.c (Arbeitskopie) @@ -3022,7 +3022,7 @@ } /* Multiply by the stride. */ - if (!integer_onep (stride)) + if (stride != NULL && !integer_onep (stride)) index = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, index, stride); Index: gcc/fortran/trans-intrinsic.c === --- gcc/fortran/trans-intrinsic.c (Revision 259739) +++ gcc/fortran/trans-intrinsic.c (Arbeitskopie) @@ -1266,34 +1266,124 @@ } else { - /* If has_vector, pass descriptor for whole array and the - vector bounds separately. */ - gfc_array_ref *ar, ar2; - bool has_vector = false; + bool has_vector = gfc_has_vector_subscript (lhs_expr); - if (gfc_is_coindexed (lhs_expr) && gfc_has_vector_subscript (lhs_expr)) + if (gfc_is_coindexed (lhs_expr) || !has_vector) { - has_vector = true; - ar = gfc_find_array_ref (lhs_expr); - ar2 = *ar; - memset (ar, '\0', sizeof (*ar)); - ar->as = ar2.as; - ar->type = AR_FULL; + /* If has_vector, pass descriptor for whole array and the + vector bounds separately. */ + gfc_array_ref *ar, ar2; + bool has_tmp_lhs_array = false; + if (has_vector) + { + has_tmp_lhs_array = true; + ar = gfc_find_array_ref (lhs_expr); + ar2 = *ar; + memset (ar, '\0', sizeof (*ar)); + ar->as = ar2.as; + ar->type = AR_FULL; + } + lhs_se.want_pointer = 1; + gfc_conv_expr_descriptor (&lhs_se, lhs_expr); + /* Using gfc_conv_expr_descriptor, we only get the descriptor, but + that has the wrong type if component references are done. */ + lhs_type = gfc_typenode_for_spec (&lhs_expr->ts); + tmp = build_fold_indirect_ref_loc (input_location, lhs_se.expr); + gfc_add_modify (&lhs_se.pre, gfc_conv_descriptor_dtype (tmp), + gfc_get_dtype_rank_type (has_vector ? ar2.dimen + : lhs_expr->rank, + lhs_type)); + if (has_tmp_lhs_array) + { + vec = conv_caf_vector_subscript (&block, lhs_se.expr, &ar2); + *ar = ar2; + } } - lhs_se.want_pointer = 1; - gfc_conv_expr_descriptor (&lhs_se