From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from 12.mo7.mail-out.ovh.net (12.mo7.mail-out.ovh.net [178.33.107.167]) by sourceware.org (Postfix) with ESMTPS id 8A2C8385840C for ; Mon, 4 Oct 2021 14:56:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8A2C8385840C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=lsferreira.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=lsferreira.net Received: from player168.ha.ovh.net (unknown [10.110.103.200]) by mo7.mail-out.ovh.net (Postfix) with ESMTP id 1FBBE1BB9D8 for ; Mon, 4 Oct 2021 16:56:52 +0200 (CEST) Received: from lsferreira.net (252.131.62.94.rev.vodafone.pt [94.62.131.252]) (Authenticated sender: contact@lsferreira.net) by player168.ha.ovh.net (Postfix) with ESMTPSA id 0FAF022D38D1B; Mon, 4 Oct 2021 14:56:51 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-96R001f816e2f4-b591-4e7d-9497-ee35b607e914, E6C02D6A25FAD5A042206508980013736C1FAC85) smtp.auth=contact@lsferreira.net X-OVh-ClientIp: 94.62.131.252 Message-ID: <202ba97937f7149bec97fafe0c821f8cc6b12304.camel@lsferreira.net> Subject: Re: [PATCH] libiberty: d-demangle: use switch instead of if-else From: =?ISO-8859-1?Q?Lu=EDs?= Ferreira To: Jeff Law , gcc-patches@gcc.gnu.org Date: Mon, 04 Oct 2021 15:56:37 +0100 In-Reply-To: <43f9005e-bc54-842b-b7c2-d3e899d8714f@gmail.com> References: <20210930010804.750229-1-contact@lsferreira.net> <43f9005e-bc54-842b-b7c2-d3e899d8714f@gmail.com> Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-nYX+HlJy3z/sZgCHtDcS" User-Agent: Evolution 3.40.4 MIME-Version: 1.0 X-Ovh-Tracer-Id: 1599903770343045143 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvtddrudelvddgkedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefkuffhvfffjghftggfggesghdtreertderjeenucfhrhhomhepnfhuvohsucfhvghrrhgvihhrrgcuoegtohhnthgrtghtsehlshhfvghrrhgvihhrrgdrnhgvtheqnecuggftrfgrthhtvghrnhepffehledtjefhheejveffvdeutedvkefhudefjedvffdvkeejueekffelgefgueeknecuffhomhgrihhnpehgohgusgholhhtrdhorhhgpdhlshhfvghrrhgvihhrrgdrnhgvthenucfkpheptddrtddrtddrtddpleegrdeivddrudefuddrvdehvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehplhgrhigvrhduieekrdhhrgdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomheptghonhhtrggttheslhhsfhgvrhhrvghirhgrrdhnvghtpdhrtghpthhtohepghgttgdqphgrthgthhgvshesghgttgdrghhnuhdrohhrgh X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, 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-List-Received-Date: Mon, 04 Oct 2021 14:56:56 -0000 --=-nYX+HlJy3z/sZgCHtDcS Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, 2021-10-03 at 15:55 -0600, Jeff Law wrote: >=20 >=20 > On 9/29/2021 7:08 PM, Lu=C3=ADs Ferreira wrote: > > This patch allows the compiler to efficiently generate jump tables > > instead of > > using if-else-if. > >=20 > > Signed-off-by: Lu=C3=ADs Ferreira > I'm not sure this is terribly useful.=C2=A0 Compilers have the ability to= =20 > analyze the underlying code and make sensible decisions for how to=20 > implement either form.=C2=A0=C2=A0 So the right metric here is does this = make the > code cleaner/easier to understand.=C2=A0 With just 3 clauses it's hard (f= or=20 > me) to make the case that it is considerably cleaner. >=20 > Jeff >=20 >=20 Well, my major point on the patch was performance, eventhough on this number of clauses it doesn't matter for GCC. I can totally agree with you. Although when we talk about a higher number of cases the optimizer reach a threashold to optimize with jump tables and if-else-if starts to loose there. Furthermore, if-else-if are hard to optimize, since the compiler need to check if the condition order is important and with a high number of cases the compiler may just give up on that check. I'm not particularly aware of how GCC theoretically optimize it, so take that with a grain of salt, but, in practice, it sure have a difference. https://godbolt.org/z/rT9drW117 Even though performance may not be terribly bad (some compilers may not be really that smart, specially in higher number of cases, as shown above) I can still consider this change for future additions, even though debatable, since mangling characters may exapand this logic and increase the number of cases making if-else-if code a bit longer to read. Overall, although, this is by far a minor thing. My intention with this was to reflect some changes I found relevant while reading this file. Side note: This was a previously sent patch. As requested by you, if this is somehow being considered to be merged, here is the changelog: ChangeLog: libiberty/ * d-demangle.c (dlang_type): Change if-else-if to switch case. --=20 Sincerely, Lu=C3=ADs Ferreira @ lsferreira.net --=-nYX+HlJy3z/sZgCHtDcS Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE0nPfaWPZzvrMTlSVcwdQ1Ut6n2YFAmFbFiUACgkQcwdQ1Ut6 n2bEyA/9FadomrWFD9yNOLJDprLuaAfuJBgk6khQlcSkXE1vP/KQSvFSJslJcfZV Nqb9tPW4JFPkjkwzpx7+FwfkPhUj4qB7tM1GbmzIYbNPnMGI7j1mjcp57qHTzndY ajJVG3GWOrcJ9X4TqDTWrrX7zxIGYdPUYD1Z+JTfjuXIZsIfKQky/yUiMbYRx5g7 wxbPaIaf8LWFGspIcHlnJtZbvV4o44pkvaTylfh4/PhyzQuZShtXdFtwW1pO4UTY /jDpPD90M8tvEDKP/tKAaghspxfbk4fqIU7iXIJhjKpLdXV7YLFZkyIvBd/2v+4z t+bf5drtAUps6uCEPk4d1l3JbZVosh8MhWAidkuZZZaL6nYQa9xYQwJ7oS1OZp+w jboVRay7l3HYFoN6Nsgx/CG9IPm36jSxfTMpxacPxSRoTMyNnx6Ivi30CPqQRp56 zpzNkoeSuIQ8XrM6WUlaI7jHzBamhfW1pKsNWSPBuHuEJMowa7OiNrCYvx4c8n9T gP5IFhKcpKUex1sW9jBe9lCeXcfRLgvT3u515VudQ++8VZEacJQEAROdTYdnAKYH DX4Iu2Fpbcew6n8UKqtgtIBEhZuN5csBzjMfY83MExxlVew3822GBN0phDOoJcq4 7OypwPSBieiQcMO1zeYhRa8r6ibF/bnkh8n2zAQPUbd9eySkZJM= =T1JX -----END PGP SIGNATURE----- --=-nYX+HlJy3z/sZgCHtDcS--