re PR fortran/56937 (Unnecessarily temporary with array-vector assignments)

2013-07-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/56937
	* dependency.c (gfc_dep_resolver):  Treat identical
	array subscripts as identical; don't unconditionally
	return a dependency if an array subscript is found.

2013-07-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/56937
	* gfortran.dg/dependency_42.f90:  New test.
	* gfortran.dg/dependency_43.f90:  New test.

From-SVN: r201094
This commit is contained in:
Thomas Koenig 2013-07-21 13:44:03 +00:00
parent 82a4f54cc5
commit 94b150705d
5 changed files with 60 additions and 3 deletions

View file

@ -1,3 +1,10 @@
2013-07-21 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/56937
* dependency.c (gfc_dep_resolver): Treat identical
array subscripts as identical; don't unconditionally
return a dependency if an array subscript is found.
2013-07-21 Tobias Burnus <burnus@net-b.de>
PR fortran/35862

View file

@ -2095,11 +2095,23 @@ gfc_dep_resolver (gfc_ref *lref, gfc_ref *rref, gfc_reverse *reverse)
for (n=0; n < lref->u.ar.dimen; n++)
{
/* Assume dependency when either of array reference is vector
subscript. */
/* Handle dependency when either of array reference is vector
subscript. There is no dependency if the vector indices
are equal or if indices are known to be different in a
different dimension. */
if (lref->u.ar.dimen_type[n] == DIMEN_VECTOR
|| rref->u.ar.dimen_type[n] == DIMEN_VECTOR)
return 1;
{
if (lref->u.ar.dimen_type[n] == DIMEN_VECTOR
&& rref->u.ar.dimen_type[n] == DIMEN_VECTOR
&& gfc_dep_compare_expr (lref->u.ar.start[n],
rref->u.ar.start[n]) == 0)
this_dep = GFC_DEP_EQUAL;
else
this_dep = GFC_DEP_OVERLAP;
goto update_fin_dep;
}
if (lref->u.ar.dimen_type[n] == DIMEN_RANGE
&& rref->u.ar.dimen_type[n] == DIMEN_RANGE)
@ -2164,6 +2176,8 @@ gfc_dep_resolver (gfc_ref *lref, gfc_ref *rref, gfc_reverse *reverse)
/* Overlap codes are in order of priority. We only need to
know the worst one.*/
update_fin_dep:
if (this_dep > fin_dep)
fin_dep = this_dep;
}

View file

@ -1,3 +1,9 @@
2013-07-21 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/56937
* gfortran.dg/dependency_42.f90: New test.
* gfortran.dg/dependency_43.f90: New test.
2013-07-21 Tobias Burnus <burnus@net-b.de>
PR fortran/35862

View file

@ -0,0 +1,16 @@
! { dg-do run }
! { dg-options "-Warray-temporaries" }
! PR fortran/56937 - unnecessary temporaries with vector indices
program main
real :: q(4), r(4), p(3)
integer :: idx(3)
p = [0.5, 1.0, 2.0]
idx = [4,3,1]
r = 1.0
r(idx) = r(idx) + p
q = 1.0
q(4) = q(4) + p(1)
q(3) = q(3) + p(2)
q(1) = q(1) + p(3)
if (any (q - r /= 0)) call abort
end

View file

@ -0,0 +1,14 @@
! { dg-do run }
! { dg-options "-Warray-temporaries" }
! PR fortran/56937 - unnecessary temporaries with vector indices
program main
integer, dimension(3) :: i1, i2
real :: a(3,2)
data a / 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 /
i1 = [ 1, 2, 3 ]
i2 = [ 3, 2, 1 ]
a (i1,1) = a (i2,2)
if (a(1,1) /= 6.0 .or. a(2,1) /= 5.0 .or. a(3,1) /= 4.0) call abort
if (a(1,2) /= 4.0 .or. a(2,2) /= 5.0 .or. a(3,2) /= 6.0) call abort
end program main