Message ID | 20230529103254.2753472-1-Jovan.Dmitrovic@Syrmia.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CF286389A262 for <patchwork@sourceware.org>; Mon, 29 May 2023 10:33:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2091.outbound.protection.outlook.com [40.107.247.91]) by sourceware.org (Postfix) with ESMTPS id 8B40E388BC81 for <gcc-patches@gcc.gnu.org>; Mon, 29 May 2023 10:33:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8B40E388BC81 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=Syrmia.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Syrmia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eH6fjdjt6hWi9da9fF1u4s4JHAQYPK6xlvSVZ10wmHYGc/CQOZBcMiGY/Gijg9WbkPsg2Ys6bhbL2NFWRlAJyW2OAboj5jQlGV5YCtXVZeQEMQC7LRW+0xU3Rg1nXSzZEMS7kzsARS8e+IJKShC72HZPhdNIu1s8Gy7LAM0gP7gjrEX98DBjwFksIr6wsnpXLYn5+AU7lrhnX7tBYDGVwAsTk8IMinAHcoI/zlPl2s2zu8nBSiNeevAbmbEi0oMXaKEDaH7hkdx/7bWoa3w75tkbzLqNDHXc8NA5a3+P2ovWPdv6rzkb3nFqWgy6bmPEsubm+2niPtMSxWUmX7w5nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vt3YcBmnVuP2gbwgnXk2s3QSu5tert5lrDEF09GJwsQ=; b=JyNKlqnadoEa5w78coXbUiJIrt3+G0sPNy4Pi1Smv7VKSYmNYuFYa2aEy0VAqK8hyBnDZyQ8oFj2/Onzm8jheBNBqZns+xm366kaouAourSgOY+3Hc2Lk4nDVLs8frJTEYwohFQBkUByrfRfr7+AQX6IHgZbQO1J9pTuui9CVI69M0U68MXwHX2fE0xGr4OZVcFkSeD670SZr7OlJbwOmBZiSByZ54e5muftf7/zgSpBGC8prehBSwGb8Q5HhogRIFes493HZw5cqg5PSZw2vmdHg9wAZNW4oCHC2OTBWZQZl6XbjWbKw4hdhFwC6Y9Z7dSctgHraOnJY1ae+nRd/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vt3YcBmnVuP2gbwgnXk2s3QSu5tert5lrDEF09GJwsQ=; b=AVHfmJOVYvU+TqJDdnAk85fwgR1C7rIXAJVaiDotI1Qlk20SjwvPqlwDDNGif3hfPrZLoDEh9bLMhCw5SPIh1K4XGkrW5YITyjK+Oglvn7twTDAAa/UkVADSRIPChFj6KCSx/tozYjbNpMjs6BDmVBIhnQ1Gv48OMO2Xd5mkqek= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=Syrmia.com; Received: from DB9PR03MB7163.eurprd03.prod.outlook.com (2603:10a6:10:1ff::9) by VI1PR03MB9939.eurprd03.prod.outlook.com (2603:10a6:800:1ce::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.22; Mon, 29 May 2023 10:33:28 +0000 Received: from DB9PR03MB7163.eurprd03.prod.outlook.com ([fe80::a3ea:bbc0:9e7b:b472]) by DB9PR03MB7163.eurprd03.prod.outlook.com ([fe80::a3ea:bbc0:9e7b:b472%7]) with mapi id 15.20.6433.022; Mon, 29 May 2023 10:33:28 +0000 From: Jovan Dmitrovic <Jovan.Dmitrovic@Syrmia.com> To: gcc-patches@gcc.gnu.org Cc: djordje.todorovic@syrmia.com, Jovan Dmitrovic <Jovan.Dmitrovic@Syrmia.com>, Jovan Dmitrovic <jovan.dmitrovic@syrmia.com> Subject: [PATCH] mips: Fix overaligned function arguments [PR109435] Date: Mon, 29 May 2023 12:32:54 +0200 Message-Id: <20230529103254.2753472-1-Jovan.Dmitrovic@Syrmia.com> X-Mailer: git-send-email 2.34.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SJ2PR07CA0011.namprd07.prod.outlook.com (2603:10b6:a03:505::20) To DB9PR03MB7163.eurprd03.prod.outlook.com (2603:10a6:10:1ff::9) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB9PR03MB7163:EE_|VI1PR03MB9939:EE_ X-MS-Office365-Filtering-Correlation-Id: 72ec4b3b-e167-4af9-1bcb-08db60302438 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: n9Tlo90W33FKkNtJJf/8f5JbZ5dxsp+i2lkBz3OMYiDbN4HZ4o7waKXb2HHEMTG2lcrhA+oMrfncGvfs807/nVOhr5hfT4oQG8jKFJFP3kgjimE3B097dXf91wd1ScmuItwIefr/SiM1B2umBFEJPpTADFMrgkFUaDctZ7DAvC9DElM2TKK+hJz1xZYt8pC8Z6WR0Q6RJGEkgq22a1xU6rxQywiJlx5OdX1w8sqXsEZwdqCXDAaH3v/vpcqNNKLFePJHWLZb6hhHsnt4q0oO9Z0VM0vRPp+WG8yu4VuG33xtJoO1U9IqA3N3za0TdEgUe+mDaR9J5YivN12yk2zqZ3v/BwQZak7bLTT0yeS0yOVD8m8pkGELAR6zlRIGaVFIaFUSefcG6gUCjbB0bTZdLXEffd+q1UH+pG3jn2DSqG5iHd4xSl7A4t3SVgni1PPHRO8LtrMVgWGPbnXcVKgKX09Bzh6vrO6vWkvZ7u8f40dIiHh8PgR3442lZJCFo8NJyku6zdk+FAS/VMJLratp6GPz7tGbsilIeXM3yTbwaLEDnbFHZGvHz/di4W7PGZ6F4GrmDEZetevjQk3/nR69FgEs9LaVqvLTkz5z0TJO2s0= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR03MB7163.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(396003)(366004)(136003)(39830400003)(376002)(346002)(451199021)(6512007)(6506007)(186003)(2906002)(2616005)(54906003)(26005)(478600001)(1076003)(84970400001)(83380400001)(52116002)(86362001)(8936002)(6486002)(38100700002)(38350700002)(41300700001)(8676002)(5660300002)(66476007)(36756003)(6666004)(316002)(66946007)(66556008)(107886003)(6916009)(4326008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BdS3Its66YG20spb/t5R2tfTUQ8ND3eULW+e/e7cFdZNrVBUwqNdC7jd7MG6ej4NmMnBtyrLpuRwVw0mhohgaieOwOyTWpMQkNwJ0oec1Iu6ERLFDrvNr2EB4mxxoVy64q/ao+Jzvjo8+Aayjd/sHdchJdeifevmErNC5HtZ2udRpcH7teyMzh1vv42CFAOhSHdVyhUsaYjaVeRf344CfEM/xkiOYx8EAH2PqEANpmZ7w3LRhXmP5pzhYX+6dN1CZ2nYEp1Zs7oJuc1Uv1+gdk5vWjVemm0ik5rIjVAc3XYB/abYRWjct7u3FFFflAblRsh0VbDvZkBX/kymOlL4ts5DrgDw29dTHOWe5PKXxSRkv9hQOxXld+WFu11gslNl71BV9lMoSyPIkx6R1z7hHSq8x+b+KCOlFI9LjGbDK6VNavhl4FZeOdU2+vGwD8Pp2bfF7hgdzGPO1nfYhkUNVGerT4a7mfkOvMQg3hHIPj51AKKIhktwJoXY3dJjL9+pxj1Ve80pIRZImxZFBBXRzRhukX+tlWstk1iKOCNsRpNaDEdQ2KeyQ+3ujmfESmOog30EZk99j4SeSgd+FxDghRZs+tFKgH7ajdQroRA8OcjKimWxVm4WYMaW70EGWItozIgRJt+11QqV4aRscfS4jrHKgRl42a477DX2etv6wV2EeuN9iavXZcxjDrXR9zpnqgKovlj6YrgZAUZvNQpYTKC1SeR7SCiZDsF9a5xs/0Lo+0icKkX3nmtGCUhhfdlhgrXbUrrcFl/uV0k6+xL3LTVx32RxqCvjTv25NtGZIf05ZVPl0BcnaFgIZKCw93R0B5tRS9oARh39ibDWXbMfIbpQYz/wlIETv0xDwttiGxI27FVoSqOScHoAFASfHtXvL+jbNUnpedhgXKULPZRsm9K95XOaO6usRckk/Hvhy9LfG+iz/SjGQYkWx2bzNKdFM+dtBVlhD5hsoRYBAbNQ7uNka2ALBPnvn+kfeU0Hg1FcbBLzIgCwq15WWHWOFkyvBR/n1jBmXWIxXkAUg3aVJt0Laf9dcVI+KancxSND5Yd2I3KJGETkpY9ow0Q7J0RBHQqBB3HHgpsSmo6DpOkKBYjELKkad8JBIMzLKBdHipDpmjeN9EqrvJCfxpO68kETRyvpIqpK+Fs7bY4ArXugg1OrBDMDZUCxvFiWCEgVtnuCVThoINGkpnyhbuz2fw46yHJDur+72iaaa68fPCVomjqKyhaaDv/I8vvz1Mgp+Pk6KqGSZcsieoFgNbJl1s4zg26ATSKjGJtMeyZEO69Frlw66Rml4VSHEoJ6b3q1wUoZsqD62hGMeO8VlQe+IZysAN/0+p2ncj3hn+f2c9b3YLvM1pCOsSmS2mFUZmPf83sxPbZgwCXMM25QsoJXMgP18M+BSFEecpS6DxZkN+5eOvNsBcjrF97scfN24a1iCDFH3bdV/HKjFVyYVQKsYyGF8ISAtlvtYvGZMekmwfB8Huhqo/cut6mkBXQA7dnoMN9+raG/KRKrxvTdOn4Ehev1YPDYi3Io2E/aAUx8ku3UfSzebCb6h4HifhFbccUms2xSGg2d65lIlNEj8v5f70+octDBrXdxTSzg+HwxtFyTgA== X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 72ec4b3b-e167-4af9-1bcb-08db60302438 X-MS-Exchange-CrossTenant-AuthSource: DB9PR03MB7163.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2023 10:33:28.8025 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nVn7cJnAOc9xprf3Dk8Rxh2qojcRaWmL/BoddLNK4yP25bDxEODMiRXRPPC52dSb3yILrgwsgpt072gcgYH7i9btJJv1fLh2jjM2As/shLo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR03MB9939 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
mips: Fix overaligned function arguments [PR109435]
|
|
Commit Message
Jovan Dmitrovic
May 29, 2023, 10:32 a.m. UTC
This patch changes alignment for typedef types when passed as
arguments, making the alignment equal to the alignment of
original (aliased) types.
This change makes it impossible for a typedef type to have
alignment that is less than its size.
Signed-off-by: Jovan Dmitrovic <jovan.dmitrovic@syrmia.com>
gcc/ChangeLog:
PR target/109435
* config/mips/mips.cc (mips_function_arg_alignment): Returns
the alignment of function argument. In case of typedef type,
it returns the aligment of the aliased type.
(mips_function_arg_boundary): Relocated calculation of the
aligment of function arguments.
gcc/testsuite/ChangeLog:
PR target/109435
* gcc.target/mips/align-1.c: New test.
---
gcc/config/mips/mips.cc | 18 +++++++++++++-
gcc/testsuite/gcc.target/mips/align-1.c | 33 +++++++++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.target/mips/align-1.c
Comments
Jovan Dmitrovic <Jovan.Dmitrovic@syrmia.com> 于2023年5月29日周一 19:00写道: > > This patch changes alignment for typedef types when passed as > arguments, making the alignment equal to the alignment of > original (aliased) types. > > This change makes it impossible for a typedef type to have > alignment that is less than its size. > > Signed-off-by: Jovan Dmitrovic <jovan.dmitrovic@syrmia.com> > > gcc/ChangeLog: > PR target/109435 > * config/mips/mips.cc (mips_function_arg_alignment): Returns > the alignment of function argument. In case of typedef type, > it returns the aligment of the aliased type. > (mips_function_arg_boundary): Relocated calculation of the > aligment of function arguments. > > gcc/testsuite/ChangeLog: > PR target/109435 > * gcc.target/mips/align-1.c: New test. > --- > gcc/config/mips/mips.cc | 18 +++++++++++++- > gcc/testsuite/gcc.target/mips/align-1.c | 33 +++++++++++++++++++++++++ > 2 files changed, 50 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gcc.target/mips/align-1.c > > diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc > index ca822758b41..2019b7cd7d9 100644 > --- a/gcc/config/mips/mips.cc > +++ b/gcc/config/mips/mips.cc > @@ -6190,6 +6190,22 @@ mips_arg_partial_bytes (cumulative_args_t cum, const function_arg_info &arg) > return info.stack_words > 0 ? info.reg_words * UNITS_PER_WORD : 0; > } > > +/* Given MODE and TYPE of a function argument, return the alignment in > + bits. In case of typedef, alignment of its original type is > + used. */ > + > +static unsigned int > +mips_function_arg_alignment (machine_mode mode, const_tree type) > +{ > + if (!type) > + return GET_MODE_ALIGNMENT (mode); > + > + if (is_typedef_decl (TYPE_NAME (type))) > + type = DECL_ORIGINAL_TYPE (TYPE_NAME (type)); > + > + return TYPE_ALIGN (type); > +} > + > /* Implement TARGET_FUNCTION_ARG_BOUNDARY. Every parameter gets at > least PARM_BOUNDARY bits of alignment, but will be given anything up > to STACK_BOUNDARY bits if the type requires it. */ > @@ -6198,8 +6214,8 @@ static unsigned int > mips_function_arg_boundary (machine_mode mode, const_tree type) > { > unsigned int alignment; > + alignment = mips_function_arg_alignment (mode, type); > > - alignment = type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode); > if (alignment < PARM_BOUNDARY) > alignment = PARM_BOUNDARY; > if (alignment > STACK_BOUNDARY) > diff --git a/gcc/testsuite/gcc.target/mips/align-1.c b/gcc/testsuite/gcc.target/mips/align-1.c > new file mode 100644 > index 00000000000..816751b8099 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/mips/align-1.c > @@ -0,0 +1,33 @@ > +/* Check that typedef alignment does not affect passing of function > + parameters. */ > +/* { dg-do run { target { "mips*-*-linux*" } } } */ Is it possible to check the result with something like scan-assembler scan-assembler-not instead of real running? > + > +#include <assert.h> > + > +typedef struct ui8 > +{ > + unsigned v[8]; > +} uint8 __attribute__ ((aligned(64))); > + > +unsigned > +callee (int x, uint8 a) > +{ > + return a.v[0]; > +} > + > +uint8 > +identity (uint8 in) > +{ > + return in; > +} > + > +int > +main (void) > +{ > + uint8 vec = {{1, 2, 3, 4, 5, 6, 7, 8}}; > + uint8 temp = identity (vec); > + unsigned temp2 = callee (1, identity (vec)); > + assert (callee (1, temp) == 1); > + assert (temp2 == 1); > + return 0; > +} > -- > 2.34.1 >
I suppose that it is possible to check assembly. Following is part of diff before and after my patch: 29,32c29,32 < sd $6,0($2) < sd $7,8($2) < sd $8,16($2) < sd $9,24($2) --- > sd $5,0($2) > sd $6,8($2) > sd $7,16($2) > sd $8,24($2) 63,66c63,66 < sd $6,0($2) < sd $7,8($2) < sd $8,16($2) < sd $9,24($2) --- > sd $5,0($2) > sd $6,8($2) > sd $7,16($2) > sd $8,24($2) 138,141c138,141 < ld $6,64($16) < ld $7,72($16) < ld $8,80($16) < ld $9,88($16) --- > ld $5,64($16) > ld $6,72($16) > ld $7,80($16) > ld $8,88($16) 148,151c148,151 < ld $6,64($16) < ld $7,72($16) < ld $8,80($16) < ld $9,88($16) --- > ld $5,64($16) > ld $6,72($16) > ld $7,80($16) > ld $8,88($16) 167,170c167,170 < ld $6,0($16) < ld $7,8($16) < ld $8,16($16) < ld $9,24($16) --- > ld $5,0($16) > ld $6,8($16) > ld $7,16($16) > ld $8,24($16) What my patch effectively does it rearranges the data in registers when invoking a function. I don't know whether writing this testcase as an assembly check would make sense, because that would make the testcase much less readable.
Jovan Dmitrovic <Jovan.Dmitrovic@syrmia.com> 于2023年6月6日周二 18:29写道: > > I suppose that it is possible to check assembly. > Great. > Following is part of diff before and after my patch: > > 29,32c29,32 > < sd $6,0($2) > < sd $7,8($2) > < sd $8,16($2) > < sd $9,24($2) > --- > > sd $5,0($2) > > sd $6,8($2) > > sd $7,16($2) > > sd $8,24($2) > 63,66c63,66 > < sd $6,0($2) > < sd $7,8($2) > < sd $8,16($2) > < sd $9,24($2) > --- > > sd $5,0($2) > > sd $6,8($2) > > sd $7,16($2) > > sd $8,24($2) > 138,141c138,141 > < ld $6,64($16) > < ld $7,72($16) > < ld $8,80($16) > < ld $9,88($16) > --- > > ld $5,64($16) > > ld $6,72($16) > > ld $7,80($16) > > ld $8,88($16) > 148,151c148,151 > < ld $6,64($16) > < ld $7,72($16) > < ld $8,80($16) > < ld $9,88($16) > --- > > ld $5,64($16) > > ld $6,72($16) > > ld $7,80($16) > > ld $8,88($16) > 167,170c167,170 > < ld $6,0($16) > < ld $7,8($16) > < ld $8,16($16) > < ld $9,24($16) > --- > > ld $5,0($16) > > ld $6,8($16) > > ld $7,16($16) > > ld $8,24($16) > > What my patch effectively does it rearranges the data in > registers when invoking a function. I don't know whether > writing this testcase as an assembly check would make sense, > because that would make the testcase much less readable. I prefer an assembly check, because the test can be used even for cross building. It is not required, I guess. > ________________________________________ > From: YunQiang Su <wzssyqa@gmail.com> > Sent: Wednesday, May 31, 2023 12:05 PM > To: Jovan Dmitrovic > Cc: gcc-patches@gcc.gnu.org; Djordje Todorovic > Subject: Re: [PATCH] mips: Fix overaligned function arguments [PR109435] > > Jovan Dmitrovic <Jovan.Dmitrovic@syrmia.com> 于2023年5月29日周一 19:00写道: > > > > This patch changes alignment for typedef types when passed as > > arguments, making the alignment equal to the alignment of > > original (aliased) types. > > > > This change makes it impossible for a typedef type to have > > alignment that is less than its size. > > > > Signed-off-by: Jovan Dmitrovic <jovan.dmitrovic@syrmia.com> > > > > gcc/ChangeLog: > > PR target/109435 > > * config/mips/mips.cc (mips_function_arg_alignment): Returns > > the alignment of function argument. In case of typedef type, > > it returns the aligment of the aliased type. > > (mips_function_arg_boundary): Relocated calculation of the > > aligment of function arguments. > > > > gcc/testsuite/ChangeLog: > > PR target/109435 > > * gcc.target/mips/align-1.c: New test. > > --- > > gcc/config/mips/mips.cc | 18 +++++++++++++- > > gcc/testsuite/gcc.target/mips/align-1.c | 33 +++++++++++++++++++++++++ > > 2 files changed, 50 insertions(+), 1 deletion(-) > > create mode 100644 gcc/testsuite/gcc.target/mips/align-1.c > > > > diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc > > index ca822758b41..2019b7cd7d9 100644 > > --- a/gcc/config/mips/mips.cc > > +++ b/gcc/config/mips/mips.cc > > @@ -6190,6 +6190,22 @@ mips_arg_partial_bytes (cumulative_args_t cum, const function_arg_info &arg) > > return info.stack_words > 0 ? info.reg_words * UNITS_PER_WORD : 0; > > } > > > > +/* Given MODE and TYPE of a function argument, return the alignment in > > + bits. In case of typedef, alignment of its original type is > > + used. */ > > + > > +static unsigned int > > +mips_function_arg_alignment (machine_mode mode, const_tree type) > > +{ > > + if (!type) > > + return GET_MODE_ALIGNMENT (mode); > > + > > + if (is_typedef_decl (TYPE_NAME (type))) > > + type = DECL_ORIGINAL_TYPE (TYPE_NAME (type)); > > + > > + return TYPE_ALIGN (type); > > +} > > + > > /* Implement TARGET_FUNCTION_ARG_BOUNDARY. Every parameter gets at > > least PARM_BOUNDARY bits of alignment, but will be given anything up > > to STACK_BOUNDARY bits if the type requires it. */ > > @@ -6198,8 +6214,8 @@ static unsigned int > > mips_function_arg_boundary (machine_mode mode, const_tree type) > > { > > unsigned int alignment; > > + alignment = mips_function_arg_alignment (mode, type); > > > > - alignment = type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode); > > if (alignment < PARM_BOUNDARY) > > alignment = PARM_BOUNDARY; > > if (alignment > STACK_BOUNDARY) > > diff --git a/gcc/testsuite/gcc.target/mips/align-1.c b/gcc/testsuite/gcc.target/mips/align-1.c > > new file mode 100644 > > index 00000000000..816751b8099 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/mips/align-1.c > > @@ -0,0 +1,33 @@ > > +/* Check that typedef alignment does not affect passing of function > > + parameters. */ > > +/* { dg-do run { target { "mips*-*-linux*" } } } */ > > Is it possible to check the result with something like > scan-assembler > scan-assembler-not > instead of real running? > > > + > > +#include <assert.h> > > + > > +typedef struct ui8 > > +{ > > + unsigned v[8]; > > +} uint8 __attribute__ ((aligned(64))); > > + > > +unsigned > > +callee (int x, uint8 a) > > +{ > > + return a.v[0]; > > +} > > + > > +uint8 > > +identity (uint8 in) > > +{ > > + return in; > > +} > > + > > +int > > +main (void) > > +{ > > + uint8 vec = {{1, 2, 3, 4, 5, 6, 7, 8}}; > > + uint8 temp = identity (vec); > > + unsigned temp2 = callee (1, identity (vec)); > > + assert (callee (1, temp) == 1); > > + assert (temp2 == 1); > > + return 0; > > +} > > -- > > 2.34.1 > >
I see what you mean now, so I've made adjustment in order for testcase to work on assembly. Following is the updated patch. Regards, Jovan From 2744357b5232c61bf1f780c4915d47b19d71f993 Mon Sep 17 00:00:00 2001 From: Jovan Dmitrovic <Jovan.Dmitrovic@Syrmia.com> Date: Fri, 19 May 2023 12:36:55 +0200 Subject: [PATCH] mips: Fix overaligned function arguments [PR109435] This patch changes alignment for typedef types when passed as arguments, making the alignment equal to the alignment of original (aliased) types. This change makes it impossible for a typedef type to have alignment that is less than its size. Signed-off-by: Jovan Dmitrovic <jovan.dmitrovic@syrmia.com> gcc/ChangeLog: PR target/109435 * config/mips/mips.cc (mips_function_arg_alignment): Returns the alignment of function argument. In case of typedef type, it returns the aligment of the aliased type. (mips_function_arg_boundary): Relocated calculation of the aligment of function arguments. gcc/testsuite/ChangeLog: PR target/109435 * gcc.target/mips/align-1.c: New test. --- gcc/config/mips/mips.cc | 19 ++++++++++++- gcc/testsuite/gcc.target/mips/align-1.c | 38 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/mips/align-1.c diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index c1d1691306e..20ba35f754c 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -6190,6 +6190,23 @@ mips_arg_partial_bytes (cumulative_args_t cum, const function_arg_info &arg) return info.stack_words > 0 ? info.reg_words * UNITS_PER_WORD : 0; } +/* Given MODE and TYPE of a function argument, return the alignment in + bits. + In case of typedef, alignment of its original type is + used. */ + +static unsigned int +mips_function_arg_alignment (machine_mode mode, const_tree type) +{ + if (!type) + return GET_MODE_ALIGNMENT (mode); + + if (is_typedef_decl (TYPE_NAME (type))) + type = DECL_ORIGINAL_TYPE (TYPE_NAME (type)); + + return TYPE_ALIGN (type); +} + /* Implement TARGET_FUNCTION_ARG_BOUNDARY. Every parameter gets at least PARM_BOUNDARY bits of alignment, but will be given anything up to STACK_BOUNDARY bits if the type requires it. */ @@ -6198,8 +6215,8 @@ static unsigned int mips_function_arg_boundary (machine_mode mode, const_tree type) { unsigned int alignment; + alignment = mips_function_arg_alignment (mode, type); - alignment = type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode); if (alignment < PARM_BOUNDARY) alignment = PARM_BOUNDARY; if (alignment > STACK_BOUNDARY) diff --git a/gcc/testsuite/gcc.target/mips/align-1.c b/gcc/testsuite/gcc.target/mips/align-1.c new file mode 100644 index 00000000000..5c639bee274 --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/align-1.c @@ -0,0 +1,38 @@ +/* Check that typedef alignment does not affect passing of function + parameters. */ +/* { dg-do compile { target { "mips*-*-linux*" } } } */ +/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */ + +#include <assert.h> + +typedef struct ui8 +{ + unsigned v[8]; +} uint8 __attribute__ ((aligned(64))); + +unsigned +callee (int x, uint8 a) +{ + return a.v[0]; +} + +uint8 +identity (uint8 in) +{ + return in; +} + +int +main (void) +{ + uint8 vec = {{1, 2, 3, 4, 5, 6, 7, 8}}; + uint8 temp = identity (vec); + unsigned temp2 = callee (1, identity (vec)); + assert (callee (1, temp) == 1); + assert (temp2 == 1); + return 0; +} + +/* { dg-final { scan-assembler "\tsd\t\\\$5,0\\(\\\$\[0-9\]\\)" } } */ +/* { dg-final { scan-assembler "\tsd\t\\\$6,8\\(\\\$\[0-9\]\\)" } } */ +/* { dg-final { scan-assembler "\tsd\t\\\$7,16\\(\\\$\[0-9\]\\)" } } */
Jovan Dmitrovic <Jovan.Dmitrovic@syrmia.com> 于2023年6月7日周三 18:29写道: > > I see what you mean now, so I've made adjustment in order for testcase to work > on assembly. Following is the updated patch. > > Regards, > Jovan > > From 2744357b5232c61bf1f780c4915d47b19d71f993 Mon Sep 17 00:00:00 2001 > From: Jovan Dmitrovic <Jovan.Dmitrovic@Syrmia.com> > Date: Fri, 19 May 2023 12:36:55 +0200 > Subject: [PATCH] mips: Fix overaligned function arguments [PR109435] > > This patch changes alignment for typedef types when passed as > arguments, making the alignment equal to the alignment of > original (aliased) types. > > This change makes it impossible for a typedef type to have > alignment that is less than its size. > > Signed-off-by: Jovan Dmitrovic <jovan.dmitrovic@syrmia.com> > > gcc/ChangeLog: > PR target/109435 > * config/mips/mips.cc (mips_function_arg_alignment): Returns > the alignment of function argument. In case of typedef type, > it returns the aligment of the aliased type. > (mips_function_arg_boundary): Relocated calculation of the > aligment of function arguments. > Please refer https://gcc.gnu.org/contribute.html about how to work with the ChangeLog. > gcc/testsuite/ChangeLog: > PR target/109435 > * gcc.target/mips/align-1.c: New test. > --- > gcc/config/mips/mips.cc | 19 ++++++++++++- > gcc/testsuite/gcc.target/mips/align-1.c | 38 +++++++++++++++++++++++++ > 2 files changed, 56 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gcc.target/mips/align-1.c > > diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc > index c1d1691306e..20ba35f754c 100644 > --- a/gcc/config/mips/mips.cc > +++ b/gcc/config/mips/mips.cc > @@ -6190,6 +6190,23 @@ mips_arg_partial_bytes (cumulative_args_t cum, const function_arg_info &arg) > return info.stack_words > 0 ? info.reg_words * UNITS_PER_WORD : 0; > } > > +/* Given MODE and TYPE of a function argument, return the alignment in > + bits. > + In case of typedef, alignment of its original type is > + used. */ > + > +static unsigned int > +mips_function_arg_alignment (machine_mode mode, const_tree type) > +{ > + if (!type) > + return GET_MODE_ALIGNMENT (mode); > + > + if (is_typedef_decl (TYPE_NAME (type))) > + type = DECL_ORIGINAL_TYPE (TYPE_NAME (type)); > + > + return TYPE_ALIGN (type); > +} > + > /* Implement TARGET_FUNCTION_ARG_BOUNDARY. Every parameter gets at > least PARM_BOUNDARY bits of alignment, but will be given anything up > to STACK_BOUNDARY bits if the type requires it. */ > @@ -6198,8 +6215,8 @@ static unsigned int > mips_function_arg_boundary (machine_mode mode, const_tree type) > { > unsigned int alignment; > + alignment = mips_function_arg_alignment (mode, type); > > - alignment = type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode); > if (alignment < PARM_BOUNDARY) > alignment = PARM_BOUNDARY; > if (alignment > STACK_BOUNDARY) > diff --git a/gcc/testsuite/gcc.target/mips/align-1.c b/gcc/testsuite/gcc.target/mips/align-1.c > new file mode 100644 > index 00000000000..5c639bee274 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/mips/align-1.c > @@ -0,0 +1,38 @@ > +/* Check that typedef alignment does not affect passing of function > + parameters. */ > +/* { dg-do compile { target { "mips*-*-linux*" } } } */ mips* may be OK, since this test looks reasonable for bare metal platforms. > +/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */ Does `-flto` required here? > + > +#include <assert.h> > + > +typedef struct ui8 > +{ > + unsigned v[8]; > +} uint8 __attribute__ ((aligned(64))); > + > +unsigned > +callee (int x, uint8 a) > +{ > + return a.v[0]; > +} > + > +uint8 > +identity (uint8 in) > +{ > + return in; > +} > + > +int > +main (void) > +{ > + uint8 vec = {{1, 2, 3, 4, 5, 6, 7, 8}}; > + uint8 temp = identity (vec); > + unsigned temp2 = callee (1, identity (vec)); > + assert (callee (1, temp) == 1); > + assert (temp2 == 1); > + return 0; > +} > + > +/* { dg-final { scan-assembler "\tsd\t\\\$5,0\\(\\\$\[0-9\]\\)" } } */ > +/* { dg-final { scan-assembler "\tsd\t\\\$6,8\\(\\\$\[0-9\]\\)" } } */ > +/* { dg-final { scan-assembler "\tsd\t\\\$7,16\\(\\\$\[0-9\]\\)" } } */ I guess, this test may fail for mips32 targets? Maybe we can add 2 tests: one for O32, and one for N32/N64. Add `-mabi=32`/`-mabi=n32` option into `dg-do compile` line. > -- > 2.34.1 > > > > > -- > YunQiang Su
Hi, I am sending a revised patch, now with different tests for N64/N32 and O32 ABIs. For the O32 ABI, I've skipped the -O0 and -Os pipelines, considering there is a difference between exact offsets for store instructions (the registers used remain the same). Skipping -flto isn't really necessary, so I've removed that part. I've fixed the Changelog, hopefully I've corrected the mistakes I made. Regards, Jovan
Jovan Dmitrovic <Jovan.Dmitrovic@syrmia.com> 于2023年6月27日周二 16:54写道: > > Hi, > I am sending a revised patch, now with different tests for N64/N32 and O32 ABIs. > For the O32 ABI, I've skipped the -O0 and -Os pipelines, considering there is a > difference between exact offsets for store instructions (the registers used remain > the same). > > Skipping -flto isn't really necessary, so I've removed that part. > > I've fixed the Changelog, hopefully I've corrected the mistakes I made. > Looks good. I will submit this patch with some format improvement. > Regards, > Jovan
YunQiang Su <wzssyqa@gmail.com> 于2023年6月29日周四 14:04写道: > > Jovan Dmitrovic <Jovan.Dmitrovic@syrmia.com> 于2023年6月27日周二 16:54写道: > > > > Hi, > > I am sending a revised patch, now with different tests for N64/N32 and O32 ABIs. > > For the O32 ABI, I've skipped the -O0 and -Os pipelines, considering there is a > > difference between exact offsets for store instructions (the registers used remain > > the same). > > > > Skipping -flto isn't really necessary, so I've removed that part. > > > > I've fixed the Changelog, hopefully I've corrected the mistakes I made. > > > > Looks good. > I will submit this patch with some format improvement. > Ohh, my fault: the `-flto` option should always be skipped, when run test. And you skipped -O0 test on O32, while this bug effects O0 only, it should not be expected. The below is my modification to your patch. Is it OK for you? --- xx.patch 2023-06-29 14:32:59.805474033 +0800 +++ build/0001-mips-Fix-overaligned-function-arguments-PR109435.patch 2023-06-29 18:01:19.245478275 +0800 @@ -1,4 +1,4 @@ -From 05e4ff4d2fbb91ea8040fb10d8d6a130ad24bba7 Mon Sep 17 00:00:00 2001 +From 7b5af22bb7c8fadce27e94c37c96101a06acd286 Mon Sep 17 00:00:00 2001 From: Jovan Dmitrovic <Jovan.Dmitrovic@Syrmia.com> Date: Mon, 26 Jun 2023 17:00:20 +0200 Subject: [PATCH] mips: Fix overaligned function arguments [PR109435] @@ -16,12 +16,13 @@ 2023-06-27 Jovan Dmitrović <jovan.dmitrovic@syrmia.com> gcc/ChangeLog: - PR target/109435 + + PR target/109435 * config/mips/mips.cc (mips_function_arg_alignment): Returns - the alignment of function argument. In case of typedef type, - it returns the aligment of the aliased type. + the alignment of function argument. In case of typedef type, + it returns the aligment of the aliased type. (mips_function_arg_boundary): Relocated calculation of the - aligment of function arguments. + aligment of function arguments. gcc/testsuite/ChangeLog: @@ -29,9 +30,9 @@ * gcc.target/mips/align-1-o32.c: New test. --- gcc/config/mips/mips.cc | 19 ++++++++++++++++++- - gcc/testsuite/gcc.target/mips/align-1-n64.c | 19 +++++++++++++++++++ + gcc/testsuite/gcc.target/mips/align-1-n64.c | 20 ++++++++++++++++++++ gcc/testsuite/gcc.target/mips/align-1-o32.c | 20 ++++++++++++++++++++ - 3 files changed, 57 insertions(+), 1 deletion(-) + 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/mips/align-1-n64.c create mode 100644 gcc/testsuite/gcc.target/mips/align-1-o32.c @@ -75,14 +76,15 @@ if (alignment > STACK_BOUNDARY) diff --git a/gcc/testsuite/gcc.target/mips/align-1-n64.c b/gcc/testsuite/gcc.target/mips/align-1-n64.c new file mode 100644 -index 00000000000..46e718d548d +index 00000000000..3ede539c3a4 --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/align-1-n64.c -@@ -0,0 +1,19 @@ +@@ -0,0 +1,20 @@ +/* Check that typedef alignment does not affect passing of function + parameters for N64/N32 ABIs. */ +/* { dg-do compile { target { "mips*-*-*" } } } */ +/* { dg-options "-mabi=64" } */ ++/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */ + +typedef struct ui8 +{ @@ -100,7 +102,7 @@ +/* { dg-final { scan-assembler "\tsd\t\\\$7,16\\(\\\$\[0-9\]\\)" } } */ diff --git a/gcc/testsuite/gcc.target/mips/align-1-o32.c b/gcc/testsuite/gcc.target/mips/align-1-o32.c new file mode 100644 -index 00000000000..a548632b7f6 +index 00000000000..e043d6a3eca --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/align-1-o32.c @@ -0,0 +1,20 @@ @@ -108,7 +110,7 @@ + parameters for O32 ABI. */ +/* { dg-do compile { target { "mips*-*-*" } } } */ +/* { dg-options "-mabi=32" } */ -+/* { dg-skip-if "" { *-*-* } { "-O0" "-Os" } { "" } } */ ++/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */ + +typedef struct ui8 +{ @@ -121,10 +123,9 @@ + return a.v[0]; +} + -+/* { dg-final { scan-assembler "\tsw\t\\\$5,100\\(\\\$sp\\)" } } */ -+/* { dg-final { scan-assembler "\tsw\t\\\$6,104\\(\\\$sp\\)" } } */ -+/* { dg-final { scan-assembler "\tsw\t\\\$7,108\\(\\\$sp\\)" } } */ ++/* { dg-final { scan-assembler "\tsw\t\\\$5,1\\d\\d\\(\\\$(sp|fp)\\)" } } */ ++/* { dg-final { scan-assembler "\tsw\t\\\$6,1\\d\\d\\(\\\$(sp|fp)\\)" } } */ ++/* { dg-final { scan-assembler "\tsw\t\\\$7,1\\d\\d\\(\\\$(sp|fp)\\)" } } */ -- -2.34.1 - +2.30.2 > > Regards, > > Jovan > > > > -- > YunQiang Su
> Ohh, my fault: the `-flto` option should always be skipped, when run test.
Right, if tests run with `-flto` option, they will fail. However, I do believe
they are run only if LTO support is enabled, that's why my tests all passed
without explicitly skipping that option.
Your modification looks good to me.
Regards,
Jovan
diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index ca822758b41..2019b7cd7d9 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -6190,6 +6190,22 @@ mips_arg_partial_bytes (cumulative_args_t cum, const function_arg_info &arg) return info.stack_words > 0 ? info.reg_words * UNITS_PER_WORD : 0; } +/* Given MODE and TYPE of a function argument, return the alignment in + bits. In case of typedef, alignment of its original type is + used. */ + +static unsigned int +mips_function_arg_alignment (machine_mode mode, const_tree type) +{ + if (!type) + return GET_MODE_ALIGNMENT (mode); + + if (is_typedef_decl (TYPE_NAME (type))) + type = DECL_ORIGINAL_TYPE (TYPE_NAME (type)); + + return TYPE_ALIGN (type); +} + /* Implement TARGET_FUNCTION_ARG_BOUNDARY. Every parameter gets at least PARM_BOUNDARY bits of alignment, but will be given anything up to STACK_BOUNDARY bits if the type requires it. */ @@ -6198,8 +6214,8 @@ static unsigned int mips_function_arg_boundary (machine_mode mode, const_tree type) { unsigned int alignment; + alignment = mips_function_arg_alignment (mode, type); - alignment = type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode); if (alignment < PARM_BOUNDARY) alignment = PARM_BOUNDARY; if (alignment > STACK_BOUNDARY) diff --git a/gcc/testsuite/gcc.target/mips/align-1.c b/gcc/testsuite/gcc.target/mips/align-1.c new file mode 100644 index 00000000000..816751b8099 --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/align-1.c @@ -0,0 +1,33 @@ +/* Check that typedef alignment does not affect passing of function + parameters. */ +/* { dg-do run { target { "mips*-*-linux*" } } } */ + +#include <assert.h> + +typedef struct ui8 +{ + unsigned v[8]; +} uint8 __attribute__ ((aligned(64))); + +unsigned +callee (int x, uint8 a) +{ + return a.v[0]; +} + +uint8 +identity (uint8 in) +{ + return in; +} + +int +main (void) +{ + uint8 vec = {{1, 2, 3, 4, 5, 6, 7, 8}}; + uint8 temp = identity (vec); + unsigned temp2 = callee (1, identity (vec)); + assert (callee (1, temp) == 1); + assert (temp2 == 1); + return 0; +}