This patch fixes the problem in two steps:
(i) It reverts r162289; and
(ii) It adds the correct initialization for loop.reverse[] in
gfc_trans_assignment_1.  This was implemented incorrectly in the fix
for PR24524 (in spite of the correct comment in dependency.c!) and
removed at sometime, I do not know why.

Bootstraps and regtests on x86_64/FC9.  OK for trunk and 4.6?

Paul

2011-05-12  Paul Thomas  <pa...@gcc.gnu.org>

        PR fortran/48955
        * dependency.c (gfc_dep_resolver): Revert r162829 which changed
        the condition for setting this_dep to GFC_DEP_OVERLAP.
        * trans-expr.c (gfc_trans_assignment_1): Enable loop reversal.

2011-05-12  Paul Thomas  <pa...@gcc.gnu.org>

        PR fortran/48955
        * gfortran.dg/dependency_40.f90 : New test.
Index: gcc/fortran/trans-expr.c
===================================================================
*** gcc/fortran/trans-expr.c	(revision 173649)
--- gcc/fortran/trans-expr.c	(working copy)
*************** gfc_trans_assignment_1 (gfc_expr * expr1
*** 6052,6057 ****
--- 6052,6061 ----
        /* Initialize the scalarizer.  */
        gfc_init_loopinfo (&loop);
  
+       /* Enable loop reversal.  */
+       for (n = 0; n < GFC_MAX_DIMENSIONS; n++)
+ 	loop.reverse[n] = GFC_CAN_REVERSE;
+ 
        /* Walk the rhs.  */
        rss = gfc_walk_expr (expr2);
        if (rss == gfc_ss_terminator)
Index: gcc/fortran/dependency.c
===================================================================
*** gcc/fortran/dependency.c	(revision 173649)
--- gcc/fortran/dependency.c	(working copy)
*************** gfc_dep_resolver (gfc_ref *lref, gfc_ref
*** 1832,1839 ****
  
  		  /* If no intention of reversing or reversing is explicitly
  		     inhibited, convert backward dependence to overlap.  */
! 		  if (this_dep == GFC_DEP_BACKWARD
! 		      && (reverse == NULL || reverse[n] == GFC_CANNOT_REVERSE))
  		    this_dep = GFC_DEP_OVERLAP;
  		}
  
--- 1832,1839 ----
  
  		  /* If no intention of reversing or reversing is explicitly
  		     inhibited, convert backward dependence to overlap.  */
! 		  if ((reverse == NULL && this_dep == GFC_DEP_BACKWARD)
! 		      || (reverse != NULL && reverse[n] == GFC_CANNOT_REVERSE))
  		    this_dep = GFC_DEP_OVERLAP;
  		}
  
Index: gcc/testsuite/gfortran.dg/dependency_40.f90
===================================================================
*** gcc/testsuite/gfortran.dg/dependency_40.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/dependency_40.f90	(revision 0)
***************
*** 0 ****
--- 1,17 ----
+ ! { dg-do run }
+ !Test the fix for PR48955, in which a temporary was not being generated for
+ ! the dependent assignment to 'V1'.
+ !
+ ! Reported by Tobias Burnus  <bur...@gcc.gnu.org>
+ !
+ program ala
+    implicit none
+    integer, parameter  :: n = 8
+    real, dimension(n) :: v0, v1, v2
+    v0 = [-10.0, -10., -10., -10., 10., 10., 10., 10.]
+    v1 = v0
+    v2 = v0
+    v1(2:n-1) = 0.5*(v1(1:n-2) + v1(3:n) + 2.0*v1(2:n-1))  ! Needs temporary
+    v2(2:n-1) = 0.5*(v0(1:n-2) + v0(3:n) + 2.0*v0(2:n-1))
+    if (any (v1 .ne. v2)) call abort
+ end program ala

Reply via email to