From patchwork Thu Jun 13 15:37:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 251095 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 8248D2C0079 for ; Fri, 14 Jun 2013 01:37:18 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:references:mime-version:content-type :in-reply-to; q=dns; s=default; b=HOwvFeavMxcoVcjb4/usZjpkPMtPiY bpRI47P+JjSAQA7dQAxTRlLLDdky1G///vd/PVuwnAdC5AYlv2yecACcLfge1u/i SELhsut8/7vS//UzMqSbfmG7u8din2HXYsX9nGJPpSTTgmSMyBwgZWqZuE+RKO6e U3cSNOll3g0aE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:references:mime-version:content-type :in-reply-to; s=default; bh=7bryRgthTKv5NvsRWFaIc/FRw88=; b=idQL Xf1rjY1m0YRzWb9RBDo9yqEZEkmuyA4B7y1yq7LVCJ6wJk2zWoCiVhw9oWfArPC9 rSHeu+l0/nBH/PCmq/7An7AXDNG4zXnSQP7RuwABlZkO2gdzG6xb/gWAsYh55HOd b87P/hvPX/KRePGSif7kYzBrLE8ZARpkK8lVaNM= Received: (qmail 9322 invoked by alias); 13 Jun 2013 15:37:09 -0000 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 Received: (qmail 9312 invoked by uid 89); 13 Jun 2013 15:37:09 -0000 X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, SPF_PASS, TW_CP autolearn=ham version=3.3.1 Received: from mail-pb0-f48.google.com (HELO mail-pb0-f48.google.com) (209.85.160.48) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 13 Jun 2013 15:37:08 +0000 Received: by mail-pb0-f48.google.com with SMTP id ma3so5011569pbc.21 for ; Thu, 13 Jun 2013 08:37:06 -0700 (PDT) X-Received: by 10.68.163.4 with SMTP id ye4mr1293678pbb.207.1371137826759; Thu, 13 Jun 2013 08:37:06 -0700 (PDT) Received: from bubble.grove.modra.org ([101.166.26.37]) by mx.google.com with ESMTPSA id v20sm29851516paj.4.2013.06.13.08.37.04 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Jun 2013 08:37:05 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 3FCCAEA009D; Fri, 14 Jun 2013 01:07:01 +0930 (CST) Date: Fri, 14 Jun 2013 01:07:01 +0930 From: Alan Modra To: Edmar Wienskoski , gcc-patches@gcc.gnu.org, David Edelsohn Subject: Re: [PATCH] DATA_ALIGNMENT vs. DATA_ABI_ALIGNMENT (PR target/56564) Message-ID: <20130613153701.GI21523@bubble.grove.modra.org> Mail-Followup-To: Edmar Wienskoski , gcc-patches@gcc.gnu.org, David Edelsohn References: <20130607192540.GH1493@tucnak.redhat.com> <51B245EF.3080602@redhat.com> <20130613074051.GG21523@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20130613074051.GG21523@bubble.grove.modra.org> User-Agent: Mutt/1.5.21 (2010-09-15) On Thu, Jun 13, 2013 at 05:10:51PM +0930, Alan Modra wrote: > On Wed, Jun 12, 2013 at 12:52:03PM -0500, Edmar Wienskoski wrote: > > The e500v2 (SPE) hardware is such that if the address of vector (double world > > load / stores) are not double world aligned the instruction will trap. > > > > So this alignment is not optional. > > Vector type alignment is also specified by the ppc64 abi. I think we > want the following. Note that DATA_ALIGNMENT has been broken for > vectors right from the initial vector support (and the error was > copied for e500 double). For example > > typedef int vec_align __attribute__ ((vector_size(16), aligned(32))); > vec_align x = { 0, 0, 0, 0 }; > > currently loses the extra alignment. Fixed by never decreasing > alignment in DATA_ABI_ALIGNMENT. Testing in progress. OK to > apply assuming bootstrap is good? (I think I need a change in > offsettable_ok_by_alignment too. I'll do that in a separate patch.) Revised patch with offsettable_ok_by_alignment change, avoiding dumb idea of using statement expressions. This one actually bootstraps and passes regression testing. * config/rs6000/rs6000.h (enum data_align): New. (LOCAL_ALIGNMENT, DATA_ALIGNMENT): Use rs6000_data_alignment. (DATA_ABI_ALIGNMENT): Define. (CONSTANT_ALIGNMENT): Correct comment. * config/rs6000/rs6000-protos.h (rs6000_data_alignment): Declare. * config/rs6000/rs6000.c (rs6000_data_alignment): New function. (offsettable_ok_by_alignment): Align by DATA_ABI_ALIGNMENT. Pass "type" not "decl" to DATA_ALIGNMENT. Index: gcc/config/rs6000/rs6000.h =================================================================== --- gcc/config/rs6000/rs6000.h (revision 200055) +++ gcc/config/rs6000/rs6000.h (working copy) @@ -813,12 +813,6 @@ extern unsigned rs6000_pointer_size; /* No data type wants to be aligned rounder than this. */ #define BIGGEST_ALIGNMENT 128 -/* A C expression to compute the alignment for a variables in the - local store. TYPE is the data type, and ALIGN is the alignment - that the object would ordinarily have. */ -#define LOCAL_ALIGNMENT(TYPE, ALIGN) \ - DATA_ALIGNMENT (TYPE, ALIGN) - /* Alignment of field after `int : 0' in a structure. */ #define EMPTY_FIELD_BOUNDARY 32 @@ -828,8 +822,15 @@ extern unsigned rs6000_pointer_size; /* A bit-field declared as `int' forces `int' alignment for the struct. */ #define PCC_BITFIELD_TYPE_MATTERS 1 -/* Make strings word-aligned so strcpy from constants will be faster. - Make vector constants quadword aligned. */ +enum data_align { align_abi, align_opt, align_both }; + +/* A C expression to compute the alignment for a variables in the + local store. TYPE is the data type, and ALIGN is the alignment + that the object would ordinarily have. */ +#define LOCAL_ALIGNMENT(TYPE, ALIGN) \ + rs6000_data_alignment (TYPE, ALIGN, align_both) + +/* Make strings word-aligned so strcpy from constants will be faster. */ #define CONSTANT_ALIGNMENT(EXP, ALIGN) \ (TREE_CODE (EXP) == STRING_CST \ && (STRICT_ALIGNMENT || !optimize_size) \ @@ -837,21 +838,14 @@ extern unsigned rs6000_pointer_size; ? BITS_PER_WORD \ : (ALIGN)) -/* Make arrays of chars word-aligned for the same reasons. - Align vectors to 128 bits. Align SPE vectors and E500 v2 doubles to +/* Make arrays of chars word-aligned for the same reasons. */ +#define DATA_ALIGNMENT(TYPE, ALIGN) \ + rs6000_data_alignment (TYPE, ALIGN, align_opt) + +/* Align vectors to 128 bits. Align SPE vectors and E500 v2 doubles to 64 bits. */ -#define DATA_ALIGNMENT(TYPE, ALIGN) \ - (TREE_CODE (TYPE) == VECTOR_TYPE \ - ? (((TARGET_SPE && SPE_VECTOR_MODE (TYPE_MODE (TYPE))) \ - || (TARGET_PAIRED_FLOAT && PAIRED_VECTOR_MODE (TYPE_MODE (TYPE)))) \ - ? 64 : 128) \ - : ((TARGET_E500_DOUBLE \ - && TREE_CODE (TYPE) == REAL_TYPE \ - && TYPE_MODE (TYPE) == DFmode) \ - ? 64 \ - : (TREE_CODE (TYPE) == ARRAY_TYPE \ - && TYPE_MODE (TREE_TYPE (TYPE)) == QImode \ - && (ALIGN) < BITS_PER_WORD) ? BITS_PER_WORD : (ALIGN))) +#define DATA_ABI_ALIGNMENT(TYPE, ALIGN) \ + rs6000_data_alignment (TYPE, ALIGN, align_abi) /* Nonzero if move instructions will actually fail to work when given unaligned data. */ Index: gcc/config/rs6000/rs6000-protos.h =================================================================== --- gcc/config/rs6000/rs6000-protos.h (revision 200055) +++ gcc/config/rs6000/rs6000-protos.h (working copy) @@ -141,6 +141,7 @@ extern int rs6000_loop_align (rtx); #endif /* RTX_CODE */ #ifdef TREE_CODE +extern unsigned int rs6000_data_alignment (tree, unsigned int, enum data_align); extern unsigned int rs6000_special_round_type_align (tree, unsigned int, unsigned int); extern unsigned int darwin_rs6000_special_round_type_align (tree, unsigned int, Index: gcc/config/rs6000/rs6000.c =================================================================== --- gcc/config/rs6000/rs6000.c (revision 200055) +++ gcc/config/rs6000/rs6000.c (working copy) @@ -5384,6 +5390,44 @@ invalid_e500_subreg (rtx op, enum machine_mode mod return false; } +/* Return alignment of TYPE. Existing alignment is ALIGN. HOW + selects whether the alignment is abi mandated, optional, or + both abi and optional alignment. */ + +unsigned int +rs6000_data_alignment (tree type, unsigned int align, enum data_align how) +{ + if (how != align_opt) + { + if (TREE_CODE (type) == VECTOR_TYPE) + { + if ((TARGET_SPE && SPE_VECTOR_MODE (TYPE_MODE (type))) + || (TARGET_PAIRED_FLOAT && PAIRED_VECTOR_MODE (TYPE_MODE (type)))) + { + if (align < 64) + align = 64; + } + else if (align < 128) + align = 128; + } + else if (TARGET_E500_DOUBLE + && TREE_CODE (type) == REAL_TYPE + && TYPE_MODE (type) == DFmode + && align < 64) + align = 64; + } + + if (how != align_abi) + { + if (TREE_CODE (type) == ARRAY_TYPE + && TYPE_MODE (TREE_TYPE (type)) == QImode + && align < BITS_PER_WORD) + align = BITS_PER_WORD; + } + + return align; +} + /* AIX increases natural record alignment to doubleword if the first field is an FP double while the FP fields remain word aligned. */ @@ -5774,10 +5818,11 @@ offsettable_ok_by_alignment (rtx op, HOST_WIDE_INT type = TREE_TYPE (decl); dalign = TYPE_ALIGN (type); + dalign = DATA_ABI_ALIGNMENT (type, dalign); if (CONSTANT_CLASS_P (decl)) dalign = CONSTANT_ALIGNMENT (decl, dalign); else - dalign = DATA_ALIGNMENT (decl, dalign); + dalign = DATA_ALIGNMENT (type, dalign); if (dsize == 0) {