From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 3FE363858431 for ; Fri, 16 Jun 2023 08:07:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3FE363858431 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-x632.google.com with SMTP id d9443c01a7336-1b51780c1b3so3628265ad.1 for ; Fri, 16 Jun 2023 01:07:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686902842; x=1689494842; 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=gA51IwHe9t8X4WlMv5Wjpt3Tvu9WlrMZ6SpwAjxFQAY=; b=bWzewHHJYmga9NsdU1mxWtU9p7bTy31sLSdwkaxy7eVSKE5ix55u/dwp36uERMGf9L jXp1DIirva0AIWbMUtD5C4Y3lWI3/uw4cdY0mgcq+o7WaaRVRPdog38Sh3rMPsJNitgW a5MVPurgWInC4BAGr5fiwtnqpoqqg/wlNaKCknBXJI24cTC2WtAoeweWD9OodI0/LSWo gtXmOHZzM/GAuegD1ikcdB1pOZ7T90pV+lhB5d+zLvBZDEkdUtL6SPI3jziR6uIti3Fp bBtehCrXIJ34A56jT1pqDstnIX2cvx7NTj9MpYNa0XNj1IfcneNy5yGT5FUumCGqOZp5 as1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686902842; x=1689494842; 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=gA51IwHe9t8X4WlMv5Wjpt3Tvu9WlrMZ6SpwAjxFQAY=; b=bjABISgdkTKhc3RWQUE9NYNcGlwHIO/dBO30bFg4fZCxeJY8m/n3+Z8eEQkazUSFiR 7lIFSfxT9K7tlNNsm8yqJ1nNqYnggBNRX1wqlhQ0jiInnYzoXhdlZxjG5qWn+Ywhsuvj C3ZX7pL7sMK1+ULCW4MQWJSMgbjUiWH5D9/2VTvDmSK+7yZ6n2sTOJNcfbizC84O0oMP 3w+QzdpmgIqkUvdN9ciN/P2Y+q6zqvp2aNUO1noK8v4K7wPYtUQJsuyxLfThOhabA6Rt cda9ZAESBeMV34tBlrzV2GCeI2BEfBrv3IVZdYzZ3PMmKC4fx3E3WX9aHbZFxnkGyM9g +kmw== X-Gm-Message-State: AC+VfDyLO8oPNAl9YDF74zrZ6y1p1PfoB6tNAQwRk/HYKA0n/eiq1qGC ruOUjoFpGRd2dwq30gFVCtDyT4YMIwDwvmjyTsI= X-Google-Smtp-Source: ACHHUZ4JC3e5LQg9pjBQwNsY4BbPb9HyU5sml+PeZ2ab3ZFJuHdoEH/l3+ptI5NBGOfssNgapHCimdhlvlgl/ECfUsU= X-Received: by 2002:a17:902:f688:b0:1b3:d4d5:beb2 with SMTP id l8-20020a170902f68800b001b3d4d5beb2mr1704010plg.9.1686902842144; Fri, 16 Jun 2023 01:07:22 -0700 (PDT) MIME-Version: 1.0 References: <20230529103254.2753472-1-Jovan.Dmitrovic@Syrmia.com> In-Reply-To: From: YunQiang Su Date: Fri, 16 Jun 2023 16:07:10 +0800 Message-ID: Subject: Re: [PATCH] mips: Fix overaligned function arguments [PR109435] To: Jovan Dmitrovic Cc: "gcc-patches@gcc.gnu.org" , Djordje Todorovic Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-6.0 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=B46=E6=9C= =887=E6=97=A5=E5=91=A8=E4=B8=89 18:29=E5=86=99=E9=81=93=EF=BC=9A > > 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 > 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 > > 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, 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 +6215,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..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 > + > +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; > +} > + > +/* { 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=3D32`/`-mabi=3Dn32` option into `dg-do compile` line. > -- > 2.34.1 > > > > > -- > YunQiang Su --=20 YunQiang Su