From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) by sourceware.org (Postfix) with ESMTPS id 582393858D20 for ; Thu, 25 May 2023 02:52:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 582393858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=xen0n.name Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xen0n.name DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1684983163; bh=FcPTQ27PmJG5sOG+DTYFCHulNJrJfIfv1dors+fpifc=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ZuOPLqhE6+45ljOHCVZclHpMsmIkzLQc490HeDDFIsumUxSwf1tILVwejb5ZIkzaq HAdDNE6piJ0qnASJUsPHjzx3qqJGOqnCmOdBdtKWcXQLwlz16YMpw1BmqNakCfjIs0 raG09WyB7d4FO9dGIZOF8jqdDsFS2U4LLjh+f7dY= Received: from [100.100.57.122] (unknown [58.34.185.106]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id C18376011B; Thu, 25 May 2023 10:52:42 +0800 (CST) Message-ID: <59f5839a-bb1e-486a-8c1c-5410ea65360e@xen0n.name> Date: Thu, 25 May 2023 10:52:42 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH] LoongArch: Fix the problem of structure parameter passing in C++. This structure has empty structure members and less than three floating point members. Content-Language: en-US To: Lulu Cheng , Jason Merrill , Jonathan Wakely Cc: Xi Ruoyao , gcc-patches@gcc.gnu.org, xuchenghua@loongson.cn References: <20230524060407.19181-1-chenglulu@loongson.cn> <2d33bf204b0d59f16df8714123ee812be5754617.camel@xry111.site> <356c3dfd86b82689483fc96f97790909a2e57c47.camel@xry111.site> From: WANG Xuerui In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_BARRACUDACENTRAL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023/5/25 10:46, Lulu Cheng wrote: > > 在 2023/5/25 上午4:15, Jason Merrill 写道: >> On Wed, May 24, 2023 at 5:00 AM Jonathan Wakely via Gcc-patches >> > wrote: >> >> On Wed, 24 May 2023 at 09:41, Xi Ruoyao wrote: >> >> > Wang Lei raised some concerns about Itanium C++ ABI, so let's >> ask a C++ >> > expert here... >> > >> > Jonathan: AFAIK the standard and the Itanium ABI treats an empty >> class >> > as size 1 >> >> Only as a complete object, not as a subobject. >> >> >> Also as a data member subobject. >> >> > in order to guarantee unique address, so for the following: >> > >> > class Empty {}; >> > class Test { Empty empty; double a, b; }; >> >> There is no need to have a unique address here, so Test::empty and >> Test::a >> have the same address. It's a potentially-overlapping subobject. >> >> For the Itanium ABI, sizeof(Test) == 2 * sizeof(double). >> >> >> That would be true if Test::empty were marked [[no_unique_address]], >> but without that attribute, sizeof(Test) is actually 3 * sizeof(double). >> >> > When we pass "Test" via registers, we may only allocate the >> registers >> > for Test::a and Test::b, and complete ignore Test::empty because >> there >> > is no addresses of registers.  Is this correct or not? >> >> I think that's a decision for the loongarch psABI. In principle, >> there's no >> reason a register has to be used to pass Test::empty, since you >> can't read >> from it or write to it. >> >> >> Agreed.  The Itanium C++ ABI has nothing to say about how registers >> are allocated for parameter passing; this is a matter for the psABI. >> >> And there is no need for a psABI to allocate a register for >> Test::empty because it contains no data. >> >> In the x86_64 psABI, Test above is passed in memory because of its >> size ("the size of the aggregate exceeds two eightbytes...").  But >> >> struct Test2 { Empty empty; double a; }; >> >> is passed in a single floating-point register; the Test2::empty >> subobject is not passed anywhere, because its eightbyte is classified >> as NO_CLASS, because there is no actual data there. > > > >> >> I know nothing about the LoongArch psABI, but going out of your way to >> assign a register to an empty class seems like a mistake. > > MIPS64 and ARM64 also allocate parameter registers for empty structs. > https://godbolt.org/z/jT4cY3T5o > > Our original intention is not to pass this empty structure member, but > to make the following two structures treat empty structure members > > in the same way in the process of passing parameters. > > struct st1 > { >     struct empty {} e1; >     long a; >     long b; > }; > > struct st2 > { >     struct empty {} e1; >     double f0; >     double f1; > }; Then shouldn't we try to avoid the extra register in all cases, instead of wasting one regardless? ;-)