summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>2013-07-21 13:44:03 +0000
committertkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>2013-07-21 13:44:03 +0000
commit7243e97994be84af55832f64e3b9dedb6ad3bc8e (patch)
treefe1ec330c9c583ea303c069de034b2b9f4ef20ce
parenteb429e06e58399fde96c4b57d5fc749606db6091 (diff)
downloadgcc-7243e97994be84af55832f64e3b9dedb6ad3bc8e.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@201094 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/fortran/ChangeLog7
-rw-r--r--gcc/fortran/dependency.c20
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gfortran.dg/dependency_42.f9016
-rw-r--r--gcc/testsuite/gfortran.dg/dependency_43.f9014
5 files changed, 60 insertions, 3 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 785cf42e9e8..f1f2437c3e3 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -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
diff --git a/gcc/fortran/dependency.c b/gcc/fortran/dependency.c
index fcdc1e50177..350c7bd07a2 100644
--- a/gcc/fortran/dependency.c
+++ b/gcc/fortran/dependency.c
@@ -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;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index cf6cef65b8c..3580ff389bc 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
diff --git a/gcc/testsuite/gfortran.dg/dependency_42.f90 b/gcc/testsuite/gfortran.dg/dependency_42.f90
new file mode 100644
index 00000000000..8f067322f9a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dependency_42.f90
@@ -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
diff --git a/gcc/testsuite/gfortran.dg/dependency_43.f90 b/gcc/testsuite/gfortran.dg/dependency_43.f90
new file mode 100644
index 00000000000..c407369c5e6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dependency_43.f90
@@ -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