public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, fortran] Optimize assignment of empty strings
@ 2012-06-06 21:48 Thomas Koenig
  2012-06-07  9:22 ` Tobias Burnus
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Koenig @ 2012-06-06 21:48 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 551 bytes --]

Hello world,

this rather simple patch makes sure that only memset is used for
assigning empty strings when front-end optimization is used.

Regression-tested.  OK for trunk?

	Thomas

2012-06-06  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-06  Thomas König  <tkoenig@gcc.gnu.org>

         PR fortran/52861
         * gfortran.dg/string_assign_1.f90:  New test case.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: p1.diff --]
[-- Type: text/x-patch; name="p1.diff", Size: 1331 bytes --]

Index: frontend-passes.c
===================================================================
--- frontend-passes.c	(Revision 188138)
+++ frontend-passes.c	(Arbeitskopie)
@@ -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_i
 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,11 +735,16 @@ 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);
 }

[-- Attachment #3: string_assign_1.f90 --]
[-- Type: text/x-fortran, Size: 361 bytes --]

! { 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" } }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch, fortran] Optimize assignment of empty strings
  2012-06-06 21:48 [patch, fortran] Optimize assignment of empty strings Thomas Koenig
@ 2012-06-07  9:22 ` Tobias Burnus
  0 siblings, 0 replies; 2+ messages in thread
From: Tobias Burnus @ 2012-06-07  9:22 UTC (permalink / raw)
  To: Thomas Koenig; +Cc: fortran, gcc-patches

Thomas Koenig wrote:
> his rather simple patch makes sure that only memset is used for
> assigning empty strings when front-end optimization is used.
>
> Regression-tested.  OK for trunk?

OK, thanks for the quick patch.

Tobias

>
> 2012-06-06  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-06  Thomas König <tkoenig@gcc.gnu.org>
>
>         PR fortran/52861
>         * gfortran.dg/string_assign_1.f90:  New test case.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-06-07  8:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-06 21:48 [patch, fortran] Optimize assignment of empty strings Thomas Koenig
2012-06-07  9:22 ` Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).