This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Fortran] Compare upper bounds in gfc_is_same_range


I've been looking into futher improving some of gfortran's dependency
analysis, and whilst looking through which routines could be reused or
adapted, I discovered a curious ommision in gfc_is_same_range.  When
comparing ranges, we currently test the stride and the lower bound,
but curiously not the upper bound!  Hence a(:5) is always considered
the same range as a(:4)??

The following patch adds additional code to check the upper bounds
the same way that we check the lower bounds.  It has been tested with
a "make bootstrap", including fortran, and regression tested with a
top-level "make -k check" with no new failures.

Ok for mainline?



2006-02-28  Roger Sayle  <roger@eyesopen.com>

	* dependency.c (gfc_is_same_range): Compare the stride, lower and
	upper bounds when testing array reference ranges for equality.


Index: dependency.c
===================================================================
*** dependency.c	(revision 111486)
--- dependency.c	(working copy)
*************** gfc_is_same_range (gfc_array_ref * ar1,
*** 150,177 ****
    /* Check the range start.  */
    e1 = ar1->start[n];
    e2 = ar2->start[n];

!   if (!(e1 || e2))
!     return 1;

!   /* Use the bound of the array if no bound is specified.  */
!   if (ar1->as && !e1)
!     e1 = ar1->as->lower[n];
!
!   if (ar2->as && !e2)
!     e2 = ar2->as->lower[n];
!
!   /* Check we have values for both.  */
!   if (!(e1 && e2))
!     return def;
!
!   i = gfc_dep_compare_expr (e1, e2);
!
!   if (i == -2)
!     return def;
!   else if (i == 0)
!     return 1;
!   return 0;
  }


--- 150,199 ----
    /* Check the range start.  */
    e1 = ar1->start[n];
    e2 = ar2->start[n];
+   if (e1 || e2)
+     {
+       /* Use the bound of the array if no bound is specified.  */
+       if (ar1->as && !e1)
+         e1 = ar1->as->lower[n];
+
+       if (ar2->as && !e2)
+         e2 = ar2->as->lower[n];
+
+       /* Check we have values for both.  */
+       if (!(e1 && e2))
+         return def;
+
+       i = gfc_dep_compare_expr (e1, e2);
+       if (i == -2)
+ 	return def;
+       else if (i != 0)
+ 	return 0;
+     }

!   /* Check the range end.  */
!   e1 = ar1->end[n];
!   e2 = ar2->end[n];
!   if (e1 || e2)
!     {
!       /* Use the bound of the array if no bound is specified.  */
!       if (ar1->as && !e1)
!         e1 = ar1->as->upper[n];
!
!       if (ar2->as && !e2)
!         e2 = ar2->as->upper[n];
!
!       /* Check we have values for both.  */
!       if (!(e1 && e2))
!         return def;
!
!       i = gfc_dep_compare_expr (e1, e2);
!       if (i == -2)
! 	return def;
!       else if (i != 0)
! 	return 0;
!     }

!   return 1;
  }


Roger
--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]