From patchwork Mon Oct 10 09:18:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 118657 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 BA6EFB700E for ; Mon, 10 Oct 2011 20:18:47 +1100 (EST) Received: (qmail 25450 invoked by alias); 10 Oct 2011 09:18:46 -0000 Received: (qmail 25442 invoked by uid 22791); 10 Oct 2011 09:18:45 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,TW_CP X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 10 Oct 2011 09:18:29 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1RDC0C-00059F-L6 from Tom_deVries@mentor.com ; Mon, 10 Oct 2011 02:18:28 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 10 Oct 2011 02:07:49 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.1.289.1; Mon, 10 Oct 2011 10:18:26 +0100 Message-ID: <4E92B854.5070208@mentor.com> Date: Mon, 10 Oct 2011 11:18:12 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.21) Gecko/20110831 Lightning/1.0b2 Thunderbird/3.1.13 MIME-Version: 1.0 To: Eric Botcazou , "gcc-patches@gcc.gnu.org" Subject: [PATCH] Mark static const strings as read-only. 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 Eric, without this patch, the mips code for the memcpy test-case in the patch looks like this. The loadbytes (lbu) and the storebytes (sb) are considered to alias, so the scheduler cannot rearrange them in a more optimal order. ... lui $2,%hi($LC0) lbu $3,%lo($LC0)($2) addiu $2,$2,%lo($LC0) sb $3,0($4) lbu $3,1($2) nop sb $3,1($4) lbu $2,2($2) j $31 sb $2,2($4) ... With the patch, the loadbytes and the storebytes are considered not to alias because the static const string src argument is marked as read-only, and the scheduler rearranges them. ... lui $3,%hi($LC0) addiu $2,$3,%lo($LC0) lbu $5,%lo($LC0)($3) lbu $3,1($2) lbu $2,2($2) sb $5,0($4) sb $3,1($4) j $31 sb $2,2($4) ... The patch makes sure that the src_mem computed here in expand_builtin_memcpy is marked as MEM_READONLY_P: ... src_mem = get_memory_rtx (src, len); ... build and reg-tested on i686, arm, and mips. OK for trunk? Thanks, - Tom 2011-10-10 Tom de Vries * gcc/emit-rtl.c (set_mem_attributes_minus_bitpos): Set MEM_READONLY_P for static const strings. * gcc/testsuite/gcc.dg/memcpy-3.c: New test. Index: gcc/emit-rtl.c =================================================================== --- gcc/emit-rtl.c (revision 179662) +++ gcc/emit-rtl.c (working copy) @@ -1696,6 +1696,11 @@ set_mem_attributes_minus_bitpos (rtx ref && !TREE_THIS_VOLATILE (base)) MEM_READONLY_P (ref) = 1; + /* Mark static const strings readonly as well. */ + if (base && TREE_CODE (base) == STRING_CST && TREE_READONLY (base) + && TREE_STATIC (base)) + MEM_READONLY_P (ref) = 1; + /* If this expression uses it's parent's alias set, mark it such that we won't change it. */ if (component_uses_parent_alias_set (t)) Index: gcc/testsuite/gcc.dg/memcpy-4.c =================================================================== --- /dev/null (new file) +++ gcc/testsuite/gcc.dg/memcpy-4.c (revision 0) @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-rtl-expand" } */ + +void +f1 (char *p) +{ + __builtin_memcpy (p, "123", 3); +} + +/* { dg-final { scan-rtl-dump-times "mem/s/u" 3 "expand" { target mips*-*-* } } } */ +/* { dg-final { cleanup-rtl-dump "expand" } } */