This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

[PATCH] Improve PR40168


This patch makes sure to not make local arrays addressable just because
we optimize zeroing to a memset in the frontend.  The middle-end is
fine with the equivalent assigment from {} (an empty CONSTRUCTOR).

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Ok for trunk (4.4?)?

Thanks,
Richard.

2009-05-18  Richard Guenther  <rguenther@suse.de>

	PR fortran/40168
	* trans-expr.c (gfc_trans_zero_assign): For local array
	destinations use an assignment from an empty constructor.

	* gfortran.dg/array_memset_2.f90: Adjust.

Index: gcc/fortran/trans-expr.c
===================================================================
*** gcc/fortran/trans-expr.c	(revision 147580)
--- gcc/fortran/trans-expr.c	(working copy)
*************** gfc_trans_zero_assign (gfc_expr * expr)
*** 4428,4438 ****
    len = fold_build2 (MULT_EXPR, gfc_array_index_type, len,
  		     fold_convert (gfc_array_index_type, tmp));
  
!   /* Convert arguments to the correct types.  */
    if (!POINTER_TYPE_P (TREE_TYPE (dest)))
!     dest = gfc_build_addr_expr (pvoid_type_node, dest);
!   else
!     dest = fold_convert (pvoid_type_node, dest);
    len = fold_convert (size_type_node, len);
  
    /* Construct call to __builtin_memset.  */
--- 4428,4441 ----
    len = fold_build2 (MULT_EXPR, gfc_array_index_type, len,
  		     fold_convert (gfc_array_index_type, tmp));
  
!   /* If we are zeroing a local array avoid taking its address by emitting
!      a = {} instead.  */
    if (!POINTER_TYPE_P (TREE_TYPE (dest)))
!     return build2 (MODIFY_EXPR, void_type_node,
! 		   dest, build_constructor (TREE_TYPE (dest), NULL));
! 
!   /* Convert arguments to the correct types.  */
!   dest = fold_convert (pvoid_type_node, dest);
    len = fold_convert (size_type_node, len);
  
    /* Construct call to __builtin_memset.  */
Index: gcc/testsuite/gfortran.dg/array_memset_2.f90
===================================================================
*** gcc/testsuite/gfortran.dg/array_memset_2.f90	(revision 147580)
--- gcc/testsuite/gfortran.dg/array_memset_2.f90	(working copy)
*************** program test
*** 20,27 ****
    data c /2*1.0/
  
    a(1,:) = 0.    ! This can't be optimized to a memset.
!   b(1,:) = 0.    ! This is optimized to memset.
!   c = 0.         ! This is optimized to memset.
    d(:,1) = 0.    ! This can't be otimized to a memset.
    call bar(e)
  
--- 20,27 ----
    data c /2*1.0/
  
    a(1,:) = 0.    ! This can't be optimized to a memset.
!   b(1,:) = 0.    ! This is optimized to = {}.
!   c = 0.         ! This is optimized to = {}.
    d(:,1) = 0.    ! This can't be otimized to a memset.
    call bar(e)
  
*************** program test
*** 33,38 ****
  
  end program
  
! ! { dg-final { scan-tree-dump-times "memset" 2 "original" } }
  ! { dg-final { cleanup-tree-dump "original" } }
  ! { dg-final { cleanup-modules "foo" } }
--- 33,38 ----
  
  end program
  
! ! { dg-final { scan-tree-dump-times "= {}" 2 "original" } }
  ! { dg-final { cleanup-tree-dump "original" } }
  ! { dg-final { cleanup-modules "foo" } }


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