From patchwork Wed Jul 9 16:06:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Weigand X-Patchwork-Id: 368261 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0B04C140116 for ; Thu, 10 Jul 2014 02:06:48 +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 :message-id:subject:to:date:from:cc:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=wwrVUccPCK5+TX3Y 441WsrxpBT3GC4/hUJ/SwQ+fi+XeSjyAMPc1BvTGkeYG1jEK+Ac36D38OUqSUefP gPWaFJasfJFiMHDwjA0lIynlTKC2cFZU6ykX34C0jmaeKCIKMyJ5dENFVhGjiBMm /JvZ3FAsRiMnXuH5HodMj3FRQDQ= 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 :message-id:subject:to:date:from:cc:mime-version:content-type :content-transfer-encoding; s=default; bh=VFa/9pgqpXM2YPyfBqK04y KTYtY=; b=yK6V69cs04O3xQIR947izvn0mUO4k1ksvVJjQN1SDn7JWIMA8x/p4L yDeI7zIOU8aWHem7wfFdMsprN++wg2bTVoobn/iAoVuraQM7UV9aurr+U8cjY+Li WxRNWsvCzM04132OgOvvvueUPW/YullNcYLPpGjGHtEMvEi4cYPXY= Received: (qmail 18931 invoked by alias); 9 Jul 2014 16:06:40 -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 18829 invoked by uid 89); 9 Jul 2014 16:06:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, MSGID_FROM_MTA_HEADER, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: e06smtp14.uk.ibm.com Received: from e06smtp14.uk.ibm.com (HELO e06smtp14.uk.ibm.com) (195.75.94.110) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 09 Jul 2014 16:06:34 +0000 Received: from /spool/local by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 9 Jul 2014 17:06:31 +0100 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 9 Jul 2014 17:06:30 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 96C201B0805F for ; Wed, 9 Jul 2014 17:07:07 +0100 (BST) Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps3074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s69G6TIr28704866 for ; Wed, 9 Jul 2014 16:06:29 GMT Received: from d06av02.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s69G6Tjl024013 for ; Wed, 9 Jul 2014 10:06:29 -0600 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with SMTP id s69G6S6v023944; Wed, 9 Jul 2014 10:06:28 -0600 Message-Id: <201407091606.s69G6S6v023944@d06av02.portsmouth.uk.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Wed, 09 Jul 2014 18:06:28 +0200 Subject: [PATCH, rs6000] Fix alignment of non-Altivec vector struct fields To: gcc-patches@gcc.gnu.org Date: Wed, 9 Jul 2014 18:06:28 +0200 (CEST) From: "Ulrich Weigand" Cc: dje.gcc@gmail.com MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14070916-1948-0000-0000-00000079B032 Hello, running the ABI compatibility test suite against another compiler showed strange effects caused by code in ADJUST_FIELD_ALIGN on rs6000: #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \ ((TARGET_ALTIVEC && TREE_CODE (TREE_TYPE (FIELD)) == VECTOR_TYPE) \ ? 128 \ : (TARGET_64BIT \ && TARGET_ALIGN_NATURAL == 0 \ && TYPE_MODE (strip_array_types (TREE_TYPE (FIELD))) == DFmode) \ ? MIN ((COMPUTED), 32) \ : (COMPUTED)) The first test for VECTOR_TYPE if TARGET_ALTIVEC causes the trouble. This has been present (in slight variations) ever since Altivec support was first merged by Aldy Hernandez back in 2001: https://gcc.gnu.org/ml/gcc-cvs/2001-11/msg00148.html Note that at this time, both ADJUST_FIELD_ALIGN and ROUND_TYPE_ALIGN contained that check. The check was later removed from ROUND_TYPE_ALIGN in the following patch intended to fix PR 17961: https://gcc.gnu.org/ml/gcc-patches/2005-06/msg00920.html The check has no effect in most usual cases anyway, since Altivec vectors already carry a default alignment of 16 bytes. However, the check *does* affect non-Altivec vectors created via attribute((vector_size)) with a size != 16. When any of those is used as element of a struct, GCC on PowerPC will ignore the normal alignment and always force 16 byte alignment. (An explicit attribute((aligned)) however, is still respected.) This behavior seems to have been unintended. In off-line discussions, we came to the conclusion that this check should have been removed from ADJUST_FIELD_ALIGN at the same time as it was removed from ROUND_TYPE_ALIGN. This patch implements this. Note that the check has been copied over time into the instances of ADJUST_FIELD_ALIGN in sysv4.h, linux64.h, and freebsd64.h. For consistency, the patch removes the check in all these places. Tested on powerpc64-linux and powerp64le-linux; built a cross-cc1 for powerpc64-freebsd6. OK for mainline? [ It may also be useful to backport to the currently open branches, but the bug was already present in many releases that are no longer maintained ... ] Bye, Ulrich Index: gcc/config/rs6000/freebsd64.h =================================================================== --- gcc/config/rs6000/freebsd64.h (revision 212147) +++ gcc/config/rs6000/freebsd64.h (working copy) @@ -365,13 +365,10 @@ #define DBX_REGISTER_NUMBER(REGNO) rs6000_dbx_register_number (REGNO) /* PowerPC64 Linux word-aligns FP doubles when -malign-power is given. */ -#undef ADJUST_FIELD_ALIGN #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \ - ((TARGET_ALTIVEC && TREE_CODE (TREE_TYPE (FIELD)) == VECTOR_TYPE) \ - ? 128 \ - : (TARGET_64BIT \ - && TARGET_ALIGN_NATURAL == 0 \ - && TYPE_MODE (strip_array_types (TREE_TYPE (FIELD))) == DFmode) \ + ((TARGET_64BIT \ + && TARGET_ALIGN_NATURAL == 0 \ + && TYPE_MODE (strip_array_types (TREE_TYPE (FIELD))) == DFmode) \ ? MIN ((COMPUTED), 32) \ : (COMPUTED)) Index: gcc/config/rs6000/linux64.h =================================================================== --- gcc/config/rs6000/linux64.h (revision 212147) +++ gcc/config/rs6000/linux64.h (working copy) @@ -244,13 +244,10 @@ do { if (TARGET_64BIT) output_profile_hook (LABEL); } while (0) /* PowerPC64 Linux word-aligns FP doubles when -malign-power is given. */ -#undef ADJUST_FIELD_ALIGN #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \ - ((TARGET_ALTIVEC && TREE_CODE (TREE_TYPE (FIELD)) == VECTOR_TYPE) \ - ? 128 \ - : (TARGET_64BIT \ - && TARGET_ALIGN_NATURAL == 0 \ - && TYPE_MODE (strip_array_types (TREE_TYPE (FIELD))) == DFmode) \ + ((TARGET_64BIT \ + && TARGET_ALIGN_NATURAL == 0 \ + && TYPE_MODE (strip_array_types (TREE_TYPE (FIELD))) == DFmode) \ ? MIN ((COMPUTED), 32) \ : (COMPUTED)) Index: gcc/config/rs6000/sysv4.h =================================================================== --- gcc/config/rs6000/sysv4.h (revision 212147) +++ gcc/config/rs6000/sysv4.h (working copy) @@ -289,12 +289,6 @@ #define ABI_STACK_BOUNDARY \ ((TARGET_EABI && !TARGET_ALTIVEC && !TARGET_ALTIVEC_ABI) ? 64 : 128) -/* An expression for the alignment of a structure field FIELD if the - alignment computed in the usual way is COMPUTED. */ -#define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \ - ((TARGET_ALTIVEC && TREE_CODE (TREE_TYPE (FIELD)) == VECTOR_TYPE) \ - ? 128 : COMPUTED) - #undef BIGGEST_FIELD_ALIGNMENT /* Use ELF style section commands. */