From patchwork Sun Aug 14 13:05:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 659030 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sBzQF1HN8z9s4n for ; Sun, 14 Aug 2016 23:05:54 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Hgy3oaEu; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=YiXx9ESLxOltyLUlb2cavFnOcfAg5OPae2zKP/dpf7Vfr8+H2d G4Y/f6DGDomOsTXvoUv1/x8WWqOeG6tsxJDchE9Nkh+5eGnq4nPT8AZLkTHJI7Gp ZE2CXQMyOKTkdiVwIy96WJut7Q3DA/1/9IknRFYhgpzLNALZEPXm/m0JQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=FLW8vu1xh6JYl0yuSPNihVhIY/E=; b=Hgy3oaEuzhdL+IYhmfg4 xOKLi5ylexiXeh2RFUKHIUg8I0m57ra0F1TDkjrW+D8dX/fKdeu5bdb6VfFG6ioS PogTK5l5Zmy2mMHlcSsfA9t6fLmz9xa5MOJM0XlPuuo5WXPQuNprjNKkOFMNnt1M 4l3m7dG5ioQmCNCyEvmii6I= Received: (qmail 51125 invoked by alias); 14 Aug 2016 13:05:48 -0000 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 Received: (qmail 51103 invoked by uid 89); 14 Aug 2016 13:05:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=rank, deferred, 239218, positives X-Spam-User: qpsmtpd, 2 recipients X-HELO: cc-smtpout3.netcologne.de Received: from cc-smtpout3.netcologne.de (HELO cc-smtpout3.netcologne.de) (89.1.8.213) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 14 Aug 2016 13:05:36 +0000 Received: from cc-smtpin1.netcologne.de (cc-smtpin1.netcologne.de [89.1.8.201]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id AB143127E1; Sun, 14 Aug 2016 15:05:33 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin1.netcologne.de (Postfix) with ESMTP id 9ECFF11E1A; Sun, 14 Aug 2016 15:05:33 +0200 (CEST) Received: from [78.35.164.95] (helo=cc-smtpin1.netcologne.de) by localhost with ESMTP (eXpurgate 4.1.8) (envelope-from ) id 57b06c9d-25d7-7f0000012729-7f000001bd86-1 for ; Sun, 14 Aug 2016 15:05:33 +0200 Received: from [192.168.178.20] (xdsl-78-35-164-95.netcologne.de [78.35.164.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by cc-smtpin1.netcologne.de (Postfix) with ESMTPSA; Sun, 14 Aug 2016 15:05:31 +0200 (CEST) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, Fortran] Fix PR 71902 Message-ID: Date: Sun, 14 Aug 2016 15:05:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 Hello world, this patch fixes the performance regression introduced with the fix for 71783. It also corrects an error in the logic in realloc_string_callback by now checking if the experssion is deferred, instead of checking for the symbol having the allocatable attribute (which led to false positives). It also checks for the presence of a substring on the RHS expression, because the problem cannot happen if there is no RHS substring. Regression-tested on trunk. OK for trunk? Also OK for a backport? Regards Thomas 2016-08-14 Thomas Koenig PR fortran/71902 * frontend-passes.c (realloc_string_callback): Check for deferred on the expression instead for allocatable on the symbol. Name temporary variable "realloc_string". 2016-08-14 Thomas Koenig PR fortran/71902 * gfortran.dg/dependency_47.f90: New test. Index: frontend-passes.c =================================================================== --- frontend-passes.c (Revision 239218) +++ frontend-passes.c (Arbeitskopie) @@ -164,6 +164,7 @@ realloc_string_callback (gfc_code **c, int *walk_s gfc_expr *expr1, *expr2; gfc_code *co = *c; gfc_expr *n; + gfc_ref *ref; if (co->op != EXEC_ASSIGN) return 0; @@ -170,7 +171,7 @@ realloc_string_callback (gfc_code **c, int *walk_s expr1 = co->expr1; if (expr1->ts.type != BT_CHARACTER || expr1->rank != 0 - || !expr1->symtree->n.sym->attr.allocatable) + || !expr1->ts.deferred) return 0; expr2 = gfc_discard_nops (co->expr2); @@ -177,6 +178,13 @@ realloc_string_callback (gfc_code **c, int *walk_s if (expr2->expr_type != EXPR_VARIABLE) return 0; + /* Only substring expressions can be affected; substrings are always the + last reference. */ + + for (ref = expr2->ref; ref; ref = ref->next) + if (ref->type != REF_SUBSTRING) + return 0; + if (!gfc_check_dependency (expr1, expr2, true)) return 0; @@ -190,7 +198,7 @@ realloc_string_callback (gfc_code **c, int *walk_s current_code = c; inserted_block = NULL; changed_statement = NULL; - n = create_var (expr2, "trim"); + n = create_var (expr2, "realloc_string"); co->expr2 = n; return 0; }