From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 F11BC384BC3A for ; Wed, 7 Sep 2022 08:20:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F11BC384BC3A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662538848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=82StYNNh1R+Ck1DIIKeCEHtSt/axihZYAhJ0ns5aUlg=; b=GnRdntgn2MXyV9zFeRzZKm83RKZsPF3PLKYp/A64iJnNi28yfor3u4KjKEf10pVM4kTZSO 0gSjfiJvNTymMBCg9sH6yfrxKRSD+CwU4m1TnacVXDrtWOwWYmWkmcoVYwTJ6cfNrY5+hl Coc2IDNrfVBW72+ANwpMAHTQVPrzJ6E= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-622-qMk0EhfjPhKZBnXGja1syA-1; Wed, 07 Sep 2022 04:20:47 -0400 X-MC-Unique: qMk0EhfjPhKZBnXGja1syA-1 Received: by mail-qv1-f69.google.com with SMTP id g4-20020ad45424000000b004a9bb302c85so4487822qvt.22 for ; Wed, 07 Sep 2022 01:20:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=82StYNNh1R+Ck1DIIKeCEHtSt/axihZYAhJ0ns5aUlg=; b=05MrBlN5ARu8q5EQolR/z+D2nHH991bh8d8l9h9IJ0C1DtMuo5xZWjRmI0C4JTDV1f J84gCBVzmtPe23CDnWlodyTHixKUcveHnQNjSMCpEmlw7pN+GMH/BSFOUQ1qiOZSTmQ8 5YGCHy770A74lhOlYWU2xf084wqW/jv2yaapF5Wff6Tg30IQ8cKBvsQA0MNPeuIpRev3 l/QOyQVT+2e/iVu4YrU6tW/o4eFmY1qCVvUVqUogjrtHEytFXh+JiCHXKVCM49d4wN7S 5toR0xC0b/P7luH/T/HXf3q42TThtyb9kJsy2Y5xq5ja6LSdZESH0BZRrSO9tDpZhbs6 Ngrg== X-Gm-Message-State: ACgBeo2kO6pxGyqu9s5hgfvQXSqE79KotYT8J1gKuAyqGfLj+Eb7Debk iQtA/3k07eOx18y0qT+11HQWb5sttMaISZmDZ+jGgLtRiPKZ8VlSIFt6JjQ9D9mfTWzrhmk3dRi BGHOxiG400JP1UOIMsVAnSyX0cLApH6c= X-Received: by 2002:a05:6214:262d:b0:4aa:1756:a3c6 with SMTP id gv13-20020a056214262d00b004aa1756a3c6mr1875632qvb.42.1662538847304; Wed, 07 Sep 2022 01:20:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR54MZV5zjXpLq1OoLRr75OB0hm9e8FvOqG/Rm96RMOFP+7fvIeDilrudfiIcl+hx2c1Z2y+vK5J8S/f+EbBKaA= X-Received: by 2002:a05:6214:262d:b0:4aa:1756:a3c6 with SMTP id gv13-20020a056214262d00b004aa1756a3c6mr1875623qvb.42.1662538847147; Wed, 07 Sep 2022 01:20:47 -0700 (PDT) MIME-Version: 1.0 References: <20220907014444.1469136-1-jason@redhat.com> In-Reply-To: <20220907014444.1469136-1-jason@redhat.com> From: Jonathan Wakely Date: Wed, 7 Sep 2022 09:20:36 +0100 Message-ID: Subject: Re: [PATCH RFA] libstdc++: small dynamic_cast optimization To: Jason Merrill Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" 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_LOW,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 List-Id: On Wed, 7 Sept 2022 at 02:45, Jason Merrill via Libstdc++ 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 (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 >