From patchwork Mon Jun 6 19:24:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 99012 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 24626B6FAF for ; Tue, 7 Jun 2011 05:25:12 +1000 (EST) Received: (qmail 25125 invoked by alias); 6 Jun 2011 19:25:10 -0000 Received: (qmail 25107 invoked by uid 22791); 6 Jun 2011 19:25:09 -0000 X-SWARE-Spam-Status: No, hits=-0.2 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cc-smtpout2.netcologne.de (HELO cc-smtpout2.netcologne.de) (89.1.8.212) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 06 Jun 2011 19:24:53 +0000 Received: from cc-smtpin3.netcologne.de (cc-smtpin3.netcologne.de [89.1.8.203]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id DA23912657; Mon, 6 Jun 2011 21:24:51 +0200 (CEST) Received: from [192.168.0.197] (xdsl-78-35-159-214.netcologne.de [78.35.159.214]) by cc-smtpin3.netcologne.de (Postfix) with ESMTPSA id 9784711E89; Mon, 6 Jun 2011 21:24:50 +0200 (CEST) Message-ID: <4DED2982.2060802@netcologne.de> Date: Mon, 06 Jun 2011 21:24:50 +0200 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.17) Gecko/20110414 SUSE/3.1.10 Thunderbird/3.1.10 MIME-Version: 1.0 To: "fortran@gcc.gnu.org" , gcc-patches Subject: Re: [patch, fortran] Some more TRIM optimizations References: <4DEBEE60.1070405@netcologne.de> In-Reply-To: <4DEBEE60.1070405@netcologne.de> 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 I wrote: > Hello world, > > the attached patch extends removing trailing TRIMs in assignments for > cases like a // trim(b). Regression-tested. OK for trunk? > > Thomas This time with the test case corrected (cleanup of the *.original file) and a more meaningful Subject line. OK? Thomas 2011-05-06 Thomas König * frontend-passes.c (optimize_assignment): Follow chains of concatenation operators to the end for removing trailing TRIMS for assignments. 2011-05-06 Thomas König * gfortran.dg/trim_optimize_7.f90: New test. ! { dg-do run } ! { dg-options "-O -fdump-tree-original" } ! Check that trailing trims are also removed from assignment of ! expressions involving concatenations of strings . program main character(2) :: a,b,c character(8) :: d a = 'a ' b = 'b ' c = 'c ' d = a // b // a // trim(c) ! This should be optimized away. if (d /= 'a b a c ') call abort d = a // trim(b) // c // a ! This shouldn't. if (d /= 'a bc a ') call abort d = a // b // a // trim(trim(c)) ! This should also be optimized away. if (d /= 'a b a c ') call abort end ! { dg-final { scan-tree-dump-times "string_len_trim" 1 "original" } } ! { dg-final { cleanup-tree-dump "original" } } Index: frontend-passes.c =================================================================== --- frontend-passes.c (Revision 174391) +++ frontend-passes.c (Arbeitskopie) @@ -500,6 +500,14 @@ optimize_assignment (gfc_code * c) if (lhs->ts.type == BT_CHARACTER) { + /* Check for a // b // trim(c). Looping is probably not + necessary because the parser usually generates + (// (// a b ) trim(c) ) , but better safe than sorry. */ + + while (rhs->expr_type == EXPR_OP + && rhs->value.op.op == INTRINSIC_CONCAT) + rhs = rhs->value.op.op2; + if (rhs->expr_type == EXPR_FUNCTION && rhs->value.function.isym && rhs->value.function.isym->id == GFC_ISYM_TRIM)