Message ID | 20220907014444.1469136-1-jason@redhat.com |
---|---|
State | New, archived |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp920946wrt; Tue, 6 Sep 2022 18:46:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR4wVvD7dfPcz8D/wW8JvWEJdv4w3H9suKfFw2YJsQZg3OuTAJwKFaRgEnzL8p1rTDhBYorF X-Received: by 2002:a17:906:c150:b0:751:288b:671d with SMTP id dp16-20020a170906c15000b00751288b671dmr758899ejc.549.1662515167373; Tue, 06 Sep 2022 18:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662515167; cv=none; d=google.com; s=arc-20160816; b=rO0v+iXYxpmIfhx8JzqdFQZgGPyTmCTRCzv9+z0yO7gJOmzksT6gCxxav5YH0/2WCO G6QrBrRwcW/SrrJVqDW+m3ZD1VDnZFog10bK0cCrYXpzrut9wCHfi/dxLjLyVUMBtdjg OrZv7r63yFcF1emXU/etYE1k9QwTqp7nCpQxbM+7p9fuNpUu3p0tIlr+dFr2GZwRVisF RI+pugLW2bDx3W7Hr8THH8nsFUYcUvJLynpg2FSvGPOCYb6nidv2buP1jMZrzKdziNUV HiUYX1gd1ua7txgL7JgfMRYpnYvx8XqDh0kYB4f6wtnYGA4uUOetcGJ3G1YC75QUfcfX uK5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=sTBvqPc3wk28L8iRNb7QaWNe9nIKAieR2TRwtrwuh5g=; b=nZC1awzA4ZrMkW/hGqkLxNidz8dRgrqKJn/mgpPpbaFFvUJbayDLfIxISc3bBTcftF Zd4XtPeTzHnj95r3LIkiJDFd/KXasEjzN4IIs4L+S1C6UaHVbk2SfVVqFd2Op2z1JNzW kLwTTdUbvXKvZQcZpByHCgVgtNafibaZ5N77KhH8+AMtazlyuhY8MiO64V984Fx1ACw5 0gG2vo4Rl7uWEtaSkQ8m0Wo8A1ksgBlxyrXupll4EHOFi6EIjog7FkGRsJ5I2gB4sxr4 BTO6Hl8H3AkK/4mFTLJFsMd4N+FVNyceoEXwRVTEGdak+JdsFBk+7SQ5pK+87sCFVCP9 fQtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=L6+uEnJC; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hd42-20020a17090796aa00b0073082518a55si11502829ejc.363.2022.09.06.18.46.07 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 18:46:07 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=L6+uEnJC; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 62260384D1BC for <ouuuleilei@gmail.com>; Wed, 7 Sep 2022 01:46:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62260384D1BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662515166; bh=sTBvqPc3wk28L8iRNb7QaWNe9nIKAieR2TRwtrwuh5g=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=L6+uEnJCX8gkDwO+2HEK6MTZJ/Ul5iOP/ZWOhD8z+etGWa/qanQrTSjGlUOtFBpdC 1EI/hgdV6Vv/tnZFBDSR9y2YqDXhtZfIbJpxczP1OldsepTLGdP71wGr8f9vRlICta 8LxZ3l68CvF0KmBP1y1mnWpAhJZuko+vfwtgf6RY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 2D7AF384D188 for <gcc-patches@gcc.gnu.org>; Wed, 7 Sep 2022 01:44:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2D7AF384D188 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-382-g0CJzgVNMSSng_M2J-c-Ug-1; Tue, 06 Sep 2022 21:44:47 -0400 X-MC-Unique: g0CJzgVNMSSng_M2J-c-Ug-1 Received: by mail-qv1-f72.google.com with SMTP id y16-20020a0cec10000000b004a5df9e16c6so4957498qvo.1 for <gcc-patches@gcc.gnu.org>; Tue, 06 Sep 2022 18:44:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=sTBvqPc3wk28L8iRNb7QaWNe9nIKAieR2TRwtrwuh5g=; b=DGuFdvctJlYBsEscU1QsaNwpDbxSey1RvmaTufv97RRO7Y3vqRoIWMShbcLcTdzYT4 BNoRNWjqbxHq1buHs6TPT51Zq6fMshOCa2w2D6z/nI2lEcmriUIAiTJKgACaNeqeiRkw QWVGuua5MjXWPy8nLntAKF1Ynu6eh9LEmvbSnLNG1sQ+T+AJRY2KUnmi20/shIB7RMh8 dO401D/uqLHHt7JekeHF7gf5eFkp4NPQEwkeNc622axxFGffbCBBwBZIaO4cewwKvb24 5jPqXHUEKwMtPGv3H7hfH32nFJtIimNcekpGCq3a7je6vgvNBF0Zp4d3wo00DVUeVK3O M5bA== X-Gm-Message-State: ACgBeo2jU29sBcNth48j0kXuLYsVWyRihr8MzefR6PFBb1kbV2scLPni hAprUKYAfOPqr6/I0/pv3yssyBNQT4ItozguP8WduxfItwLOP1S3qBDLjF9/PAfW1VoEi20jmEP jr9MofgrbGe1bopuJiAVf1C7XVnMrqg4zDwGpTqdYD5K2YlyEt3RnJWasm7sBwl+Ppg== X-Received: by 2002:a05:622a:1305:b0:344:9050:79dc with SMTP id v5-20020a05622a130500b00344905079dcmr1326443qtk.335.1662515087092; Tue, 06 Sep 2022 18:44:47 -0700 (PDT) X-Received: by 2002:a05:622a:1305:b0:344:9050:79dc with SMTP id v5-20020a05622a130500b00344905079dcmr1326424qtk.335.1662515086751; Tue, 06 Sep 2022 18:44:46 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id n76-20020a37404f000000b006baed2827f2sm12217666qka.44.2022.09.06.18.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 18:44:46 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH RFA] libstdc++: small dynamic_cast optimization Date: Tue, 6 Sep 2022 21:44:44 -0400 Message-Id: <20220907014444.1469136-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Jason Merrill via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Jason Merrill <jason@redhat.com> Cc: libstdc++@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743273504049123619?= X-GMAIL-MSGID: =?utf-8?q?1743273504049123619?= |
Series |
[RFA] libstdc++: small dynamic_cast optimization
|
|
Commit Message
Jason Merrill
Sept. 7, 2022, 1:44 a.m. UTC
An email discussion of optimizing EH led me to wonder why we weren't doing this already. Not that this change affects EH at all. Tested x86_64-pc-linux-gnu. Does this seem worthwhile? libstdc++-v3/ChangeLog: * libsupc++/dyncast.cc (__dynamic_cast): Avoid virtual function call in simple success case. --- libstdc++-v3/libsupc++/dyncast.cc | 6 ++++++ 1 file changed, 6 insertions(+) base-commit: 0a2fba3697411c07a8330abfe7460ce62bce5e7f
Comments
On Wed, 7 Sept 2022 at 02:45, Jason Merrill via Libstdc++ <libstdc++@gcc.gnu.org> wrote: > > An email discussion of optimizing EH led me to wonder why we weren't doing > this already. Not that this change affects EH at all. > > Tested x86_64-pc-linux-gnu. Does this seem worthwhile? Yes, I think so. If there's a fast path, we should take it. > > libstdc++-v3/ChangeLog: > > * libsupc++/dyncast.cc (__dynamic_cast): Avoid virtual function > call in simple success case. > --- > libstdc++-v3/libsupc++/dyncast.cc | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/libstdc++-v3/libsupc++/dyncast.cc b/libstdc++-v3/libsupc++/dyncast.cc > index 853c911a4cf..616e4c05766 100644 > --- a/libstdc++-v3/libsupc++/dyncast.cc > +++ b/libstdc++-v3/libsupc++/dyncast.cc > @@ -71,6 +71,12 @@ __dynamic_cast (const void *src_ptr, // object started from > if (whole_prefix->whole_type != whole_type) > return NULL; > > + // Avoid virtual function call in the simple success case. > + if (src2dst >= 0 > + && src2dst == -prefix->whole_object > + && *whole_type == *dst_type) > + return const_cast <void *> (whole_ptr); > + > whole_type->__do_dyncast (src2dst, __class_type_info::__contained_public, > dst_type, whole_ptr, src_type, src_ptr, result); > if (!result.dst_ptr) > > base-commit: 0a2fba3697411c07a8330abfe7460ce62bce5e7f > -- > 2.31.1 >
diff --git a/libstdc++-v3/libsupc++/dyncast.cc b/libstdc++-v3/libsupc++/dyncast.cc index 853c911a4cf..616e4c05766 100644 --- a/libstdc++-v3/libsupc++/dyncast.cc +++ b/libstdc++-v3/libsupc++/dyncast.cc @@ -71,6 +71,12 @@ __dynamic_cast (const void *src_ptr, // object started from if (whole_prefix->whole_type != whole_type) return NULL; + // Avoid virtual function call in the simple success case. + if (src2dst >= 0 + && src2dst == -prefix->whole_object + && *whole_type == *dst_type) + return const_cast <void *> (whole_ptr); + whole_type->__do_dyncast (src2dst, __class_type_info::__contained_public, dst_type, whole_ptr, src_type, src_ptr, result); if (!result.dst_ptr)