From patchwork Wed Apr 27 11:45:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 1622987 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=elakn9+D; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpH5f5jg5z9s3q for ; Wed, 27 Apr 2022 21:46:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D291E3857822 for ; Wed, 27 Apr 2022 11:46:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D291E3857822 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1651059986; bh=k/K6Xdem0mzs6DIxVJD6x9STUAZMNdlgircyo/cEMs4=; h=Subject:To:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=elakn9+DCh15peOwDy21Xe9S0+mzfrJBFkriss4cTZ3t6VNeGQj6kb19OlZD2apN6 P2umSZqVjqINfQe0L74V7fxR7+SzvCQAk/TQZ7b/WXDS3yWu3uCe2I5uKCeiFZ3rkh HjcqRVS3uevBhgd2P+VnBYCxBVZxDVQLpJ6AH/Ls= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mengyan1223.wang (mengyan1223.wang [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id C29193858405 for ; Wed, 27 Apr 2022 11:46:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C29193858405 Received: from localhost.localdomain (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@mengyan1223.wang) by mengyan1223.wang (Postfix) with ESMTPSA id CB3F56655D; Wed, 27 Apr 2022 07:46:02 -0400 (EDT) Message-ID: <4e6b1850a2cfdc05e8a27d5c2c8216a82302a104.camel@mengyan1223.wang> Subject: [PATCH v2] loongarch: ignore zero-size fields in calling convention To: Lulu Cheng , Xi Ruoyao via Gcc-patches Date: Wed, 27 Apr 2022 19:45:59 +0800 In-Reply-To: References: <4ec7e7a716cb0ca090983f0400c99c50bc67bcb3.camel@mengyan1223.wang> <0b6d4a0f77bf88df6ad2182c1f56c77573f2e336.camel@mengyan1223.wang> <8b0045aa-df0f-e217-58c7-a31e466fd1cc@loongson.cn> User-Agent: Evolution 3.44.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3036.3 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Xi Ruoyao via Gcc-patches From: Xi Ruoyao Reply-To: Xi Ruoyao Cc: Chenghua Xu , Xuerui Wang Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" On Wed, 2022-04-27 at 14:57 +0800, Lulu Cheng wrote: > I think the modification should be below. > > > > > > >              if (!TYPE_P (TREE_TYPE (f))) > > > >                 return -1; I think (!TYPE_P (TREE_TYPE (f)) will never be true (the code handling calling convention of other ports does not has this check). But "first thing first" so I'll move the change below this for now. gcc/ * config/loongarch/loongarch.cc (loongarch_flatten_aggregate_field): Ignore empty fields for RECORD_TYPE. gcc/testsuite/ * gcc.target/loongarch/zero-size-field-pass.c: New test. * gcc.target/loongarch/zero-size-field-ret.c: New test. --- gcc/config/loongarch/loongarch.cc | 3 ++ .../loongarch/zero-size-field-pass.c | 30 +++++++++++++++++++ .../loongarch/zero-size-field-ret.c | 28 +++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 gcc/testsuite/gcc.target/loongarch/zero-size-field-pass.c create mode 100644 gcc/testsuite/gcc.target/loongarch/zero-size-field-ret.c diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index f22150a60cc..80046b64006 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -329,6 +329,9 @@ loongarch_flatten_aggregate_field (const_tree type, if (!TYPE_P (TREE_TYPE (f))) return -1; + if (DECL_SIZE (f) && integer_zerop (DECL_SIZE (f))) + continue; + HOST_WIDE_INT pos = offset + int_byte_position (f); n = loongarch_flatten_aggregate_field (TREE_TYPE (f), fields, n, pos); diff --git a/gcc/testsuite/gcc.target/loongarch/zero-size-field-pass.c b/gcc/testsuite/gcc.target/loongarch/zero-size-field-pass.c new file mode 100644 index 00000000000..999dc913a71 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/zero-size-field-pass.c @@ -0,0 +1,30 @@ +/* Test that LoongArch backend ignores zero-sized fields of aggregates in + argument passing. */ + +/* { dg-do compile } */ +/* { dg-options "-O2 -mdouble-float -mabi=lp64d" } */ +/* { dg-final { scan-assembler "\\\$f1" } } */ + +struct test +{ + int empty1[0]; + double empty2[0]; + int : 0; + float x; + long empty3[0]; + long : 0; + float y; + unsigned : 0; + char empty4[0]; +}; + +extern void callee (struct test); + +void +caller (void) +{ + struct test test; + test.x = 114; + test.y = 514; + callee (test); +} diff --git a/gcc/testsuite/gcc.target/loongarch/zero-size-field-ret.c b/gcc/testsuite/gcc.target/loongarch/zero-size-field-ret.c new file mode 100644 index 00000000000..40137d97555 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/zero-size-field-ret.c @@ -0,0 +1,28 @@ +/* Test that LoongArch backend ignores zero-sized fields of aggregates in + returning. */ + +/* { dg-do compile } */ +/* { dg-options "-O2 -mdouble-float -mabi=lp64d" } */ +/* { dg-final { scan-assembler-not "\\\$r4" } } */ + +struct test +{ + int empty1[0]; + double empty2[0]; + int : 0; + float x; + long empty3[0]; + long : 0; + float y; + unsigned : 0; + char empty4[0]; +}; + +extern struct test callee (void); + +float +caller (void) +{ + struct test test = callee (); + return test.x + test.y; +}