http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52861

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |tkoenig at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #3 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2012-06-06 
18:08:10 UTC ---
This should be rather simple.  Not-yet-regression-tested patch:

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

Reply via email to