From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id 004B03857C51 for ; Wed, 31 May 2023 10:05:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 004B03857C51 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1b0424c5137so27969505ad.1 for ; Wed, 31 May 2023 03:05:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685527529; x=1688119529; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xA1+8UsFEU1WlGHnZjtbjW5+Iod7fehoFKU6ooBOVv4=; b=sblZQ6WrUNaukQx7NlZB1jSHKmM64U+YkxmaRTqdH9w6e8gwq6Qc6B+dUQUc9ZV/sa Jdf6RBYd2uakhQYGl2cMJeB9b/WLFiaX7ChS1XHNjImcEFSFz+jQTxMO5owPJ9t4oWLm V7GpwV7Zro/GIG7uta1+oqjKrXcij6qYzyogmMA4EMgFHXLpNzswCa6uzfRcQ3kvh1uv ImTuBTdDNnqZ5usis7bzpyz+CXQUKB7mLsKiPBL1RoF8hprPiNfEGtK0aD7CePgZe3Tr /JrTO7JoaAmfx1HHP9CdHtuMOdoFNnjQqT68g6fxpke4iHTfkqOYDoOiIcVe6Pjj2HjL tH/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685527529; x=1688119529; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xA1+8UsFEU1WlGHnZjtbjW5+Iod7fehoFKU6ooBOVv4=; b=gZOpYe6BO3OGMl8AjGKOV+0kmI8UFqm8Cvr25SRB6/JBrFrKK+wIlnwa1Iq4Q6+JDL +w77X/rzZzyF77X2B+s+JUK7TX6cG3StIzZ9XJQqcoaj88hqI76g1qFZlGM1eubK1Bf+ BYCB0bvfd9kTx9tE9A70b0dwlj56diWvj97+tc4tdAvAw79IZMceAaijouug8JlByfBH 1OZSnYZndnylLsN70GQrHX/nQXOPRGnvaPwfq664QlN0Wv3DIlbTdjA9DeXzr8uIJCOo WXHxhLa9JmuAffM/S6N/WfJjM1S0h8qqx2IPZGhDtV4iiPXEXeOPZEqnbxg+C5f0XYhL 9h/g== X-Gm-Message-State: AC+VfDwEjj1oA5JQZkiumgVmBbgbzSyHkQcSla+MSP7hlpk2BlHjx69h rLPbGeQuRBPpzhFAuR+mHCoNgAtPU9YJMmaQHiA= X-Google-Smtp-Source: ACHHUZ7hkFb/s/RzkDnM4+j/hcDmQJczMezF9yxACdiVrzpHS5TNg4mnzhZy5jbHyQl8YpQARbBTyTVhwAAJKcvtGIE= X-Received: by 2002:a17:902:c244:b0:1b0:26f0:4c72 with SMTP id 4-20020a170902c24400b001b026f04c72mr4930251plg.28.1685527528735; Wed, 31 May 2023 03:05:28 -0700 (PDT) MIME-Version: 1.0 References: <20230529103254.2753472-1-Jovan.Dmitrovic@Syrmia.com> In-Reply-To: <20230529103254.2753472-1-Jovan.Dmitrovic@Syrmia.com> From: YunQiang Su Date: Wed, 31 May 2023 18:05:17 +0800 Message-ID: Subject: Re: [PATCH] mips: Fix overaligned function arguments [PR109435] To: Jovan Dmitrovic Cc: gcc-patches@gcc.gnu.org, djordje.todorovic@syrmia.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 List-Id: Jovan Dmitrovic =E4=BA=8E2023=E5=B9=B45=E6=9C= =8829=E6=97=A5=E5=91=A8=E4=B8=80 19:00=E5=86=99=E9=81=93=EF=BC=9A > > 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 > > 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, con= st 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 =3D 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 =3D mips_function_arg_alignment (mode, type); > > - alignment =3D type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode); > if (alignment < PARM_BOUNDARY) > alignment =3D 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 > + > +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 =3D {{1, 2, 3, 4, 5, 6, 7, 8}}; > + uint8 temp =3D identity (vec); > + unsigned temp2 =3D callee (1, identity (vec)); > + assert (callee (1, temp) =3D=3D 1); > + assert (temp2 =3D=3D 1); > + return 0; > +} > -- > 2.34.1 > --=20 YunQiang Su