From bfa31dad8a7ae5febc3a03fe6004d589019b77b2 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Mon, 18 May 2009 10:24:34 +0000 Subject: [PATCH] re PR tree-optimization/40168 (finding common subexpressions) 2009-05-18 Richard Guenther 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. From-SVN: r147659 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/trans-expr.c | 11 +++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/array_memset_2.f90 | 6 +++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index a47a3eeb7f7..7a37d0e123b 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2009-05-18 Richard Guenther + + PR fortran/40168 + * trans-expr.c (gfc_trans_zero_assign): For local array + destinations use an assignment from an empty constructor. + 2009-05-18 Janus Weil PR fortran/36947 diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index cf17598c9f6..a20d3ae8892 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -4428,11 +4428,14 @@ gfc_trans_zero_assign (gfc_expr * expr) len = fold_build2 (MULT_EXPR, gfc_array_index_type, len, fold_convert (gfc_array_index_type, tmp)); - /* Convert arguments to the correct types. */ + /* If we are zeroing a local array avoid taking its address by emitting + a = {} instead. */ if (!POINTER_TYPE_P (TREE_TYPE (dest))) - dest = gfc_build_addr_expr (pvoid_type_node, dest); - else - dest = fold_convert (pvoid_type_node, 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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b79f8c0a778..73dc40866fa 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-05-18 Richard Guenther + + PR fortran/40168 + * gfortran.dg/array_memset_2.f90: Adjust. + 2009-05-18 Janus Weil PR fortran/36947 diff --git a/gcc/testsuite/gfortran.dg/array_memset_2.f90 b/gcc/testsuite/gfortran.dg/array_memset_2.f90 index 58ce8fe6442..7805f7b9420 100644 --- a/gcc/testsuite/gfortran.dg/array_memset_2.f90 +++ b/gcc/testsuite/gfortran.dg/array_memset_2.f90 @@ -20,8 +20,8 @@ program test 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. + 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) @@ -33,6 +33,6 @@ program test end program -! { dg-final { scan-tree-dump-times "memset" 2 "original" } } +! { dg-final { scan-tree-dump-times "= {}" 2 "original" } } ! { dg-final { cleanup-tree-dump "original" } } ! { dg-final { cleanup-modules "foo" } }