From patchwork Wed Jun 6 21:30:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 163431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 31FF9B6FA1 for ; Thu, 7 Jun 2012 07:30:54 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1339623055; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=OA5K8DA 3Q35iLsLtGaEIkV8J0VU=; b=RbYJVbLiTVmmo9IWKbOrR6M07SAKNC9gChLoY7n y9rKfI0CbUpavqocX/5Pyr//XhfKfCVIdPSLXViRnEwbIYnfEumwpzhSQBQ4mstc TNiEXqtmDyRXIZTikYbVCBhunS34vGmij6K3f/Z6EkipM5C1ogGWvS8ddqjuSQ5K YZCs= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=MqSgXwcyurnUcG5lnekushOErqtV1cHRjAGJZvTTGchslpN4YJaANOxvBj1pRM 8J9u11fs3oHjMDPJ+ALDif5Ze0UahE15Ifljfdte21POkfF0dXwxBRV5cHRGrSOU UqHM7LHJvmdRQ9tTtXG02oy1aSwxF0C/h9h07usGsPmOs=; Received: (qmail 5639 invoked by alias); 6 Jun 2012 21:30:50 -0000 Received: (qmail 5624 invoked by uid 22791); 6 Jun 2012 21:30:49 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_NO, TW_CP, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cc-smtpout3.netcologne.de (HELO cc-smtpout3.netcologne.de) (89.1.8.213) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 06 Jun 2012 21:30:36 +0000 Received: from cc-smtpin3.netcologne.de (cc-smtpin3.netcologne.de [89.1.8.203]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id AC18812A1F; Wed, 6 Jun 2012 23:30:33 +0200 (CEST) Received: from [192.168.0.106] (xdsl-78-35-173-148.netcologne.de [78.35.173.148]) by cc-smtpin3.netcologne.de (Postfix) with ESMTPSA id 8302811D8D; Wed, 6 Jun 2012 23:30:32 +0200 (CEST) Message-ID: <4FCFCBF7.2050805@netcologne.de> Date: Wed, 06 Jun 2012 23:30:31 +0200 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120421 Thunderbird/12.0 MIME-Version: 1.0 To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, fortran] Optimize assignment of empty strings Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 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 PR fortran/52861 * gfortran.dg/string_assign_1.f90: New test case. 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); }