From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17745 invoked by alias); 24 Aug 2007 12:34:35 -0000 Received: (qmail 17445 invoked by uid 22791); 24 Aug 2007 12:34:33 -0000 X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 24 Aug 2007 12:34:29 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx2.redhat.com (8.13.1/8.13.1) with ESMTP id l7OCYQLK026143; Fri, 24 Aug 2007 08:34:27 -0400 Received: from devserv.devel.redhat.com (devserv.devel.redhat.com [172.16.58.1]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l7OCYQkF032514; Fri, 24 Aug 2007 08:34:26 -0400 Received: from devserv.devel.redhat.com (localhost.localdomain [127.0.0.1]) by devserv.devel.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id l7OCYQxA016074; Fri, 24 Aug 2007 08:34:26 -0400 Received: (from jakub@localhost) by devserv.devel.redhat.com (8.12.11.20060308/8.12.11/Submit) id l7OCYQPg016072; Fri, 24 Aug 2007 08:34:26 -0400 Date: Fri, 24 Aug 2007 13:42:00 -0000 From: Jakub Jelinek To: Richard Guenther Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Optimize var = STRING_CST Message-ID: <20070824123426.GF2063@devserv.devel.redhat.com> Reply-To: Jakub Jelinek References: <20070823212347.GC2063@devserv.devel.redhat.com> <84fc9c000708240237s7c1cd305g5c40b44a3a0f3484@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ZOudaV4lSIjFTlHv" Content-Disposition: inline In-Reply-To: <84fc9c000708240237s7c1cd305g5c40b44a3a0f3484@mail.gmail.com> User-Agent: Mutt/1.4.1i 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/msg01643.txt.bz2 --ZOudaV4lSIjFTlHv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 435 On Fri, Aug 24, 2007 at 11:37:25AM +0200, Richard Guenther wrote: > This is ok if you add a testcase. Thanks, attached patch is what I have committed. > I also bet we have a PR somewhere for this one... PR31150 is related, but this patch is just a very partial improvement for that case and only on some arches (e.g. both ppc32 and ppc64 won't use store_by_pieces on the testcase below for neither foo nor bar function). Jakub --ZOudaV4lSIjFTlHv Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=M2 Content-length: 4166 2007-08-24 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. * gcc.dg/array-init-1.c: New test. --- gcc/builtins.c.jj 2007-08-23 23:31:24.000000000 +0200 +++ gcc/builtins.c 2007-08-23 23:38:22.000000000 +0200 @@ -125,7 +125,6 @@ static rtx expand_builtin_bcopy (tree, i static rtx expand_builtin_strcpy (tree, tree, rtx, enum machine_mode); static rtx expand_builtin_strcpy_args (tree, tree, tree, rtx, enum machine_mode); static rtx expand_builtin_stpcpy (tree, rtx, enum machine_mode); -static rtx builtin_strncpy_read_str (void *, HOST_WIDE_INT, enum machine_mode); static rtx expand_builtin_strncpy (tree, rtx, enum machine_mode); static rtx builtin_memset_gen_str (void *, HOST_WIDE_INT, enum machine_mode); static rtx expand_builtin_memset (tree, rtx, enum machine_mode); @@ -3734,7 +3733,7 @@ expand_builtin_stpcpy (tree exp, rtx tar bytes from constant string DATA + OFFSET and return it as target constant. */ -static rtx +rtx builtin_strncpy_read_str (void *data, HOST_WIDE_INT offset, enum machine_mode mode) { --- gcc/expr.h.jj 2007-08-23 23:31:24.000000000 +0200 +++ gcc/expr.h 2007-08-23 23:38:22.000000000 +0200 @@ -341,6 +341,7 @@ extern void expand_builtin_setjmp_setup extern void expand_builtin_setjmp_receiver (rtx); extern rtx expand_builtin_saveregs (void); extern void expand_builtin_trap (void); +extern rtx builtin_strncpy_read_str (void *, HOST_WIDE_INT, enum machine_mode); /* Functions from expr.c: */ --- gcc/expr.c.jj 2007-08-23 23:31:02.000000000 +0200 +++ gcc/expr.c 2007-08-23 23:38:22.000000000 +0200 @@ -4472,10 +4472,52 @@ store_expr (tree exp, rtx target, int ca return NULL_RTX; } + else if (TREE_CODE (exp) == STRING_CST + && !nontemporal && !call_param_p + && TREE_STRING_LENGTH (exp) > 0 + && TYPE_MODE (TREE_TYPE (exp)) == BLKmode) + { + /* Optimize initialization of an array with a STRING_CST. */ + HOST_WIDE_INT exp_len, str_copy_len; + rtx dest_mem; + + exp_len = int_expr_size (exp); + if (exp_len <= 0) + goto normal_expr; + + str_copy_len = strlen (TREE_STRING_POINTER (exp)); + if (str_copy_len < TREE_STRING_LENGTH (exp) - 1) + goto normal_expr; + + str_copy_len = TREE_STRING_LENGTH (exp); + if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0) + { + str_copy_len += STORE_MAX_PIECES - 1; + str_copy_len &= ~(STORE_MAX_PIECES - 1); + } + str_copy_len = MIN (str_copy_len, exp_len); + if (!can_store_by_pieces (str_copy_len, builtin_strncpy_read_str, + (void *) TREE_STRING_POINTER (exp), + MEM_ALIGN (target))) + goto normal_expr; + + dest_mem = target; + + dest_mem = store_by_pieces (dest_mem, + str_copy_len, builtin_strncpy_read_str, + (void *) TREE_STRING_POINTER (exp), + MEM_ALIGN (target), + exp_len > str_copy_len ? 1 : 0); + if (exp_len > str_copy_len) + clear_storage (dest_mem, GEN_INT (exp_len - str_copy_len), + BLOCK_OP_NORMAL); + return NULL_RTX; + } else { rtx tmp_target; + normal_expr: /* If we want to use a nontemporal store, force the value to register first. */ tmp_target = nontemporal ? NULL_RTX : target; --- gcc/testsuite/gcc.dg/array-init-1.c.jj 2007-08-24 14:12:19.000000000 +0200 +++ gcc/testsuite/gcc.dg/array-init-1.c 2007-08-24 14:22:50.000000000 +0200 @@ -0,0 +1,24 @@ +/* Test that both arrays are initialized by store_by_pieces. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +struct A { char c[10]; }; +extern void baz (struct A *); + +void +foo (void) +{ + struct A a = { "abcdefghi" }; + baz (&a); +} + +void +bar (void) +{ + struct A a; + __builtin_strcpy (&a.c[0], "abcdefghi"); + baz (&a); +} + +/* { dg-final { scan-assembler-not "abcdefghi" { target i?86-*-* x86_64-*-* ia64-*-* } } } */ +/* { dg-final { scan-assembler-times "7523094288207667809\|6867666564636261\|1684234849\|64636261" 2 { target i?86-*-* x86_64-*-* ia64-*-* } } } */ --ZOudaV4lSIjFTlHv--