From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12643 invoked by alias); 24 Aug 2007 09:37:35 -0000 Received: (qmail 12585 invoked by uid 22791); 24 Aug 2007 09:37:34 -0000 X-Spam-Check-By: sourceware.org Received: from py-out-1112.google.com (HELO py-out-1112.google.com) (64.233.166.181) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 24 Aug 2007 09:37:27 +0000 Received: by py-out-1112.google.com with SMTP id a29so1768540pyi for ; Fri, 24 Aug 2007 02:37:25 -0700 (PDT) Received: by 10.65.224.11 with SMTP id b11mr5130458qbr.1187948245546; Fri, 24 Aug 2007 02:37:25 -0700 (PDT) Received: by 10.65.240.11 with HTTP; Fri, 24 Aug 2007 02:37:25 -0700 (PDT) Message-ID: <84fc9c000708240237s7c1cd305g5c40b44a3a0f3484@mail.gmail.com> Date: Fri, 24 Aug 2007 09:59:00 -0000 From: "Richard Guenther" To: "Jakub Jelinek" Subject: Re: [PATCH] Optimize var = STRING_CST Cc: gcc-patches@gcc.gnu.org In-Reply-To: <20070823212347.GC2063@devserv.devel.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20070823212347.GC2063@devserv.devel.redhat.com> X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2007-08/txt/msg01627.txt.bz2 On 8/23/07, Jakub Jelinek wrote: > Hi! > > The following patch optimizes initialization of an array from a STRING_CST. > Without this patch store_expr will always force the STRING_CST into memory > and then do a block move from there, followed by optional clear_storage > if the STRING_CST is shorter than the array. This patch uses > store_by_pieces if possible. > With the patch: > struct A { char c[10]; }; > > void > foo (void) > { > struct A a = { "abcdefghi" }; > baz (&a); > } > > void > bar (void) > { > struct A a; > __builtin_strcpy (&a.c[0], "abcdefghi"); > baz (&a); > } > both routines are the same on x86_64 except for > slightly different register allocation, without that patch > for foo a .LC0 constant with the string literal is emitted and foo > copies over from that string into a.c array. > > Tested on x86_64-linux, ok for trunk? This is ok if you add a testcase. I also bet we have a PR somewhere for this one... Thanks, Richard. > 2007-08-23 Jakub Jelinek > > * expr.c (store_expr): Optimize initialization of an array > with STRING_CST. > * expr.h (builtin_strncpy_read_str): New prototype. > * builtins.c (builtin_strncpy_read_str): Remove prototype. > No longer static.