From patchwork Mon Oct 11 20:41:10 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 67480 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 A7574B70CB for ; Tue, 12 Oct 2010 07:41:22 +1100 (EST) Received: (qmail 15666 invoked by alias); 11 Oct 2010 20:41:21 -0000 Received: (qmail 15657 invoked by uid 22791); 11 Oct 2010 20:41:20 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD 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; Mon, 11 Oct 2010 20:41:13 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9BKfBYO014058 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 11 Oct 2010 16:41:12 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9BKfAdj013397 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 11 Oct 2010 16:41:11 -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 o9BKfAEf008850 for ; Mon, 11 Oct 2010 22:41:10 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o9BKfA95008848 for gcc-patches@gcc.gnu.org; Mon, 11 Oct 2010 22:41:10 +0200 Date: Mon, 11 Oct 2010 22:41:10 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] MEM = "abcd" expansion improvements Message-ID: <20101011204110.GI2082@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) 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! This patch slightly cleans up MEM = STRING_CST and MEM = MEM_REF<&STRING_CST, 0> expansion by sharing the code for STRING_CST and MEM_REF<&STRING_CST, 0> and allows it even for non-BLKmode mode - e.g. for "abcd" the mode is SImode, but as long as target is MEM it is desirable to optimize it using store_by_pieces. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2010-10-11 Jakub Jelinek * expr.c (store_expr): Share code for STRING_CST and MEM_REF of &STRING_CST cases. Don't require BLKmode, instead check if target is a MEM. Jakub --- gcc/expr.c.jj 2010-10-11 07:51:09.000000000 +0200 +++ gcc/expr.c 2010-10-11 13:46:05.000000000 +0200 @@ -4636,62 +4636,26 @@ store_expr (tree exp, rtx target, int ca return NULL_RTX; } - else if (TREE_CODE (exp) == STRING_CST + else if ((TREE_CODE (exp) == STRING_CST + || (TREE_CODE (exp) == MEM_REF + && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) + == STRING_CST + && integer_zerop (TREE_OPERAND (exp, 1)))) && !nontemporal && !call_param_p - && TREE_STRING_LENGTH (exp) > 0 - && TYPE_MODE (TREE_TYPE (exp)) == BLKmode) + && MEM_P (target)) { /* Optimize initialization of an array with a STRING_CST. */ HOST_WIDE_INT exp_len, str_copy_len; rtx dest_mem; + tree str = TREE_CODE (exp) == STRING_CST + ? exp : TREE_OPERAND (TREE_OPERAND (exp, 0), 0); 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, - CONST_CAST(char *, TREE_STRING_POINTER (exp)), - MEM_ALIGN (target), false)) - goto normal_expr; - - dest_mem = target; - - dest_mem = store_by_pieces (dest_mem, - str_copy_len, builtin_strncpy_read_str, - CONST_CAST(char *, TREE_STRING_POINTER (exp)), - MEM_ALIGN (target), false, - exp_len > str_copy_len ? 1 : 0); - if (exp_len > str_copy_len) - clear_storage (adjust_address (dest_mem, BLKmode, 0), - GEN_INT (exp_len - str_copy_len), - BLOCK_OP_NORMAL); - return NULL_RTX; - } - else if (TREE_CODE (exp) == MEM_REF - && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR - && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) == STRING_CST - && integer_zerop (TREE_OPERAND (exp, 1)) - && !nontemporal && !call_param_p - && 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; - tree str = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); - - exp_len = int_expr_size (exp); - if (exp_len <= 0) + if (TREE_STRING_LENGTH (str) <= 0) goto normal_expr; str_copy_len = strlen (TREE_STRING_POINTER (str)); @@ -4699,14 +4663,15 @@ store_expr (tree exp, rtx target, int ca goto normal_expr; str_copy_len = TREE_STRING_LENGTH (str); - if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0) + if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0 + && TREE_STRING_POINTER (str)[TREE_STRING_LENGTH (str) - 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, - CONST_CAST(char *, TREE_STRING_POINTER (str)), + CONST_CAST (char *, TREE_STRING_POINTER (str)), MEM_ALIGN (target), false)) goto normal_expr; @@ -4714,7 +4679,8 @@ store_expr (tree exp, rtx target, int ca dest_mem = store_by_pieces (dest_mem, str_copy_len, builtin_strncpy_read_str, - CONST_CAST(char *, TREE_STRING_POINTER (str)), + CONST_CAST (char *, + TREE_STRING_POINTER (str)), MEM_ALIGN (target), false, exp_len > str_copy_len ? 1 : 0); if (exp_len > str_copy_len)