From patchwork Thu Sep 29 13:02:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 116948 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 6BA6E1007D4 for ; Thu, 29 Sep 2011 23:03:00 +1000 (EST) Received: (qmail 26900 invoked by alias); 29 Sep 2011 13:02:55 -0000 Received: (qmail 26891 invoked by uid 22791); 29 Sep 2011 13:02:54 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_CP X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 29 Sep 2011 13:02:20 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p8TD2KeG013938 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 29 Sep 2011 09:02:20 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p8TD2IIq018125 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 29 Sep 2011 09:02:19 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p8TD2Hv7022642; Thu, 29 Sep 2011 15:02:18 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p8TD2Hsb022641; Thu, 29 Sep 2011 15:02:17 +0200 Date: Thu, 29 Sep 2011 15:02:17 +0200 From: Jakub Jelinek To: Richard Guenther Cc: gcc-patches@gcc.gnu.org Subject: [wwwdocs] Re: [2/2] tree-ssa-strlen optimization pass Message-ID: <20110929130217.GU2687@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek References: <20110915170922.GR2687@tyan-ft48-01.lab.bos.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! On Mon, Sep 26, 2011 at 04:33:05PM +0200, Richard Guenther wrote: > Btw, can you add a changes.html entry for this? Like this? Jakub --- htdocs/gcc-4.7/changes.html 27 Sep 2011 18:42:56 -0000 1.38 +++ htdocs/gcc-4.7/changes.html 29 Sep 2011 12:56:42 -0000 @@ -124,6 +124,48 @@ void bar (void) possibly only by inlining all calls. Cloning causes a lot less code size growth. + +
  • String length optimization pass has been added. This pass attempts + to track string lengths and optimize various standard C string functions + like strlen, strchr, strcpy, + strcat, stpcpy and their + _FORTIFY_SOURCE counterparts into faster alternatives. + This pass is enabled by default at -O2 or above, unless + optimizing for size, and can be disabled by + -fno-optimize-strlen option. The pass can e.g. optimize +
    +char *bar (const char *a)
    +{
    +  size_t l = strlen (a) + 2;
    +  char *p = malloc (l); if (p == NULL) return p;
    +  strcpy (p, a); strcat (p, "/"); return p;
    +}
    +      
    + can be optimized into: +
    +char *bar (const char *a)
    +{
    +  size_t tmp = strlen (a);
    +  char *p = malloc (tmp + 2); if (p == NULL) return p;
    +  memcpy (p, a, tmp); memcpy (p + tmp, "/", 2); return p;
    +}
    +      
    + or for hosted compilations where stpcpy is available in the + runtime and headers provide its prototype, e.g. +
    +void foo (char *a, const char *b, const char *c, const char *d)
    +{
    +  strcpy (a, b); strcat (a, c); strcat (a, d);
    +}
    +      
    + into: +
    +void foo (char *a, const char *b, const char *c, const char *d)
    +{
    +  strcpy (stpcpy (stpcpy (a, b), c), d);
    +}
    +      
    +
  • New Languages and Language specific improvements