diff options
author | Thomas Koenig <tkoenig@gcc.gnu.org> | 2012-06-07 11:11:55 +0000 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2012-06-07 11:11:55 +0000 |
commit | 94d145bf5bb4260cb02d43434ab48eb6d6ffe0cd (patch) | |
tree | 45b7207b0fa91090d90b3a9db729bafd16702830 /gcc | |
parent | d8a5e488d5a4df076006e84e2ad3e31b74501e13 (diff) | |
download | gcc-94d145bf5bb4260cb02d43434ab48eb6d6ffe0cd.zip gcc-94d145bf5bb4260cb02d43434ab48eb6d6ffe0cd.tar.gz gcc-94d145bf5bb4260cb02d43434ab48eb6d6ffe0cd.tar.bz2 |
re PR fortran/52861 ((missed optimisation) missed transformation to memset with -O3)
2012-06-07 Thomas König <tkoenig@gcc.gnu.org>
PR fortran/52861
* frontend-passes (empty_string): Add prototype.
(optimize_assignment): Set the length of an empty string
constant to zero.
2012-06-07 Thomas König <tkoenig@gcc.gnu.org>
PR fortran/52861
* gfortran.dg/string_assign_1.f90: New test case.
From-SVN: r188300
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/fortran/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/fortran/frontend-passes.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/string_assign_1.f90 | 11 |
4 files changed, 33 insertions, 4 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index b3342ab..c882a41 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2012-06-07 Thomas König <tkoenig@gcc.gnu.org> + + PR fortran/52861 + * frontend-passes (empty_string): Add prototype. + (optimize_assignment): Set the length of an empty string + constant to zero. + 2012-06-04 Tobias Burnus <burnus@net-b.de> PR fortran/50619 diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index 40ca074..4fd24c2 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -1,5 +1,5 @@ /* Pass manager for Fortran front end. - Copyright (C) 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc. Contributed by Thomas König. This file is part of GCC. @@ -37,6 +37,7 @@ static bool optimize_comparison (gfc_expr *, gfc_intrinsic_op); static bool optimize_trim (gfc_expr *); static bool optimize_lexical_comparison (gfc_expr *); static void optimize_minmaxloc (gfc_expr **); +static bool empty_string (gfc_expr *e); /* How deep we are inside an argument list. */ @@ -734,10 +735,15 @@ optimize_assignment (gfc_code * c) lhs = c->expr1; rhs = c->expr2; - /* Optimize away a = trim(b), where a is a character variable. */ - if (lhs->ts.type == BT_CHARACTER) - remove_trim (rhs); + { + /* Optimize away a = trim(b), where a is a character variable. */ + remove_trim (rhs); + + /* Replace a = ' ' by a = '' to optimize away a memcpy. */ + if (empty_string(rhs)) + rhs->value.character.length = 0; + } if (lhs->rank > 0 && gfc_check_dependency (lhs, rhs, true) == 0) optimize_binop_array_assignment (c, &rhs, false); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2ba217f..5819c00 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-06-07 Thomas König <tkoenig@gcc.gnu.org> + + PR fortran/52861 + * gfortran.dg/string_assign_1.f90: New test case. + 2012-06-07 Jakub Jelinek <jakub@redhat.com> PR middle-end/53580 diff --git a/gcc/testsuite/gfortran.dg/string_assign_1.f90 b/gcc/testsuite/gfortran.dg/string_assign_1.f90 new file mode 100644 index 0000000..8a520ff --- /dev/null +++ b/gcc/testsuite/gfortran.dg/string_assign_1.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! { dg-options "-ffrontend-optimize -fdump-tree-original" } +! PR 52861 - optimize this to c = '' so that there is +! no memcpy in the generated code. +program main + character (len=20) :: c + c = ' ' + print *,c +end program main +! { dg-final { scan-tree-dump-times "memcpy" 0 "original" } } +! { dg-final { cleanup-tree-dump "original" } } |