]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/45159 (Unnecessary temporaries)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Fri, 6 Aug 2010 22:33:37 +0000 (22:33 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Fri, 6 Aug 2010 22:33:37 +0000 (22:33 +0000)
2010-08-06  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/45159
* dependency.c (check_section_vs_section):  Handle cases where
the start expression coincides with the lower or upper
bound of the array.

2010-08-06  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/45159
* gfortran.dg/dependency_31.f90:  New test.

From-SVN: r162966

gcc/fortran/ChangeLog
gcc/fortran/dependency.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/dependency_31.f90 [new file with mode: 0644]

index 752b187c6f60af93c072966da9af93b9124c5eff..fa2aaa65505c7e8f0375d15310574f21c5f8fe32 100644 (file)
@@ -1,3 +1,10 @@
+2010-08-06  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/45159
+       * dependency.c (check_section_vs_section):  Handle cases where
+       the start expression coincides with the lower or upper
+       bound of the array.
+
 2010-08-04  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/42207
index 90b2d679ec929d46f9a4840679d7da43adb37513..dfb0c94e541d65b556483ead1d11c0140cf08735 100644 (file)
@@ -1196,13 +1196,33 @@ check_section_vs_section (gfc_array_ref *l_ar, gfc_array_ref *r_ar, int n)
        return GFC_DEP_FORWARD;
     }
 
-  /* Check for backward dependencies:
-     Are the strides the same?.  */
+
+  /*  Are the strides the same?  */
   if ((!l_stride && !r_stride)
        ||
       (l_stride && r_stride
        && gfc_dep_compare_expr (l_stride, r_stride) == 0))
     {
+
+      if (l_start && IS_ARRAY_EXPLICIT (l_ar->as))
+       {
+
+         /* Check for a(low:y:s) vs. a(z:a:s) where a has a lower bound
+            of low, which is always at least a forward dependence.  */
+
+         if (r_dir == 1
+             && gfc_dep_compare_expr (l_start, l_ar->as->lower[n]) == 0)
+           return GFC_DEP_FORWARD;
+
+         /* Check for a(high:y:-s) vs. a(z:a:-s) where a has a higher bound
+            of high, which is always at least a forward dependence.  */
+
+         if (r_dir == -1
+             && gfc_dep_compare_expr (l_start, l_ar->as->upper[n]) == 0)
+           return GFC_DEP_FORWARD;
+       }
+
+      /* From here, check for backwards dependencies.  */
       /* x:y vs. x+1:z.  */
       if (l_dir == 1 && r_dir == 1
            && l_start && r_start
index 49a72cd6c3db3ae073927a2bf6697eebf457205b..e39d0450bde103fa9c3793c642488f8145a1dfd6 100644 (file)
@@ -1,3 +1,8 @@
+2010-08-06  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/45159
+       * gfortran.dg/dependency_31.f90:  New test.
+
 2010-08-06  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        * gfortran.dg/dependency_30.f90:  Fix incorrect dg-do line.
diff --git a/gcc/testsuite/gfortran.dg/dependency_31.f90 b/gcc/testsuite/gfortran.dg/dependency_31.f90
new file mode 100644 (file)
index 0000000..afab249
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! { dg-options "-Warray-temporaries" }
+! PR 45159 - make sure no temporary is created for this.
+subroutine foo(a,n,i,j)
+  implicit none
+  integer, intent(in) :: i,j,n
+  real, dimension(20) :: a
+  a(1:10) = a(i:j)
+  a(20:n:-3) = a(n:i:-3)
+end subroutine foo