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 705B5385841A for ; Wed, 24 Aug 2022 23:03:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 705B5385841A 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=1661382188; 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=XEGvHkWbdcFw1cC6tBFjDnfkNmVK01vnp5PB4y5oOUk=; b=K1KCKjZrQmQIWST+v5SVM+UprNCE+GT5nS41wjkuXeXVv6EuDjUAzPAfV4i8pJZ+vv2p7B YYfvVbJ38ZeP930OBR187FD4eUnWOZP6sAshX3PZDkt+xpwAix11GiLWdwY7TXq4/3S1qv YIjcLT21rd1V93kxFgJclkXQWUn3zmM= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-654-D5x9Pc6LN8KQ5SwGAM0ppQ-1; Wed, 24 Aug 2022 19:03:07 -0400 X-MC-Unique: D5x9Pc6LN8KQ5SwGAM0ppQ-1 Received: by mail-qv1-f70.google.com with SMTP id cv17-20020ad44d91000000b00496b9fdf13bso10523196qvb.22 for ; Wed, 24 Aug 2022 16:03:07 -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; bh=XEGvHkWbdcFw1cC6tBFjDnfkNmVK01vnp5PB4y5oOUk=; b=eNHHBsq4LiH/wuSX3IKa6S60pxSfN/LF6WwCnjfD6/6LzDaaiCPNP9lt9NpCazaxzw Ndgd0nGgUBr2ywt/oVbAN6/QKFo9QzP0ehR7aKjxw2JcjLb3JC2LoV/cE4TVAvk7wpAs Ul/LxHuHchhQtC5jUAvQx5mMxIEiSAl4ytgscKlcN2tTVO9sOVNHe8drNvRlLt5r3qV7 nRJriAQCyd5aUOO43PSxuJrJ1bHdVDyiOicr+Dl/4/uDAO7GH1Pfyow2INkS/Q+aM0Gf svEE62Jb0k49GiO8r/bCNFX0Eo7yyOsvaAXW0KO46McxjUtipjPHd9PIa43z65amj3ME 5KJQ== X-Gm-Message-State: ACgBeo2rlqeRv7DFiXuwru8NeMHPJ1C2OuJZt77v1jgiV46VC1gfI3+q 1S6a+lGSCZqJYIYHtb4QOkNvVJ4WlDvpoxe1ZzI0S2xIRyr6JOtHnVppVE95HICsWqRcnXlQs33 I53qhI8PoU3j62Fz5eMXNpJDmdMf3BPg= X-Received: by 2002:a05:622a:11c2:b0:343:69d:65b2 with SMTP id n2-20020a05622a11c200b00343069d65b2mr1367884qtk.491.1661382186636; Wed, 24 Aug 2022 16:03:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR59qs9frwK03U0BuSKI1HewROZLU1bL8InHtwGmCrjKGn+r8WYhqKcMWnsbwmCFSDWQ8B9PP9pRnaYWpfy3mA4= X-Received: by 2002:a05:622a:11c2:b0:343:69d:65b2 with SMTP id n2-20020a05622a11c200b00343069d65b2mr1367863qtk.491.1661382186408; Wed, 24 Aug 2022 16:03:06 -0700 (PDT) MIME-Version: 1.0 References: <20220822181509.1032874-2-whh8b@obs.cr> <20220824061648.1119635-1-whh8b@obs.cr> <20220824061648.1119635-2-whh8b@obs.cr> In-Reply-To: From: Jonathan Wakely Date: Thu, 25 Aug 2022 00:02:55 +0100 Message-ID: Subject: Re: [PATCH] libstdc++: Optimize operator+(string/char*, string/char*) equally To: Alexandre Oliva Cc: Jonathan Wakely via Gcc-patches , whh8b@obs.cr, 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=-13.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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, 24 Aug 2022 at 23:47, Jonathan Wakely wrote: > > On Wed, 24 Aug 2022 at 23:39, Alexandre Oliva wrote: > > > > On Aug 24, 2022, Jonathan Wakely via Gcc-patches wrote: > > > > > * include/bits/basic_string.h (operator+(const string&, > > > const char*)): > > > Remove naive implementation. > > > * include/bits/basic_string.tcc (operator+(const string&, > > > const char*)): > > > Add single-allocation implementation. > > > > ISTM this requires the following additional tweak: > > > > diff --git a/libstdc++-v3/src/c++11/string-inst.cc b/libstdc++-v3/src/c++11/string-inst.cc > > index bfae6d902a1dd..2ec0e9d85f947 100644 > > --- a/libstdc++-v3/src/c++11/string-inst.cc > > +++ b/libstdc++-v3/src/c++11/string-inst.cc > > @@ -58,6 +58,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > > > template class basic_string; > > template S operator+(const C*, const S&); > > + template S operator+(const S&, const C*); > > template S operator+(C, const S&); > > template S operator+(const S&, const S&); > > > > > > Without this, I'm getting undefined references to this specialization in > > libstdc++.so, that I tracked down to a std::system_error ctor in > > cxx11-ios_failure.o. I got this while testing another patch that might > > be the reason why the template instantiation doesn't get inlined, but... > > we can't depend on its being inlined, can we? > > Right. But adding that will cause another symbol to be exported, > probably with the wrong symbol version. Oh, but those symbols aren't exported ... they're just needed because we compile with -fno-implicit-templatesand other symbols in libstdc++.so require them. So that probably is the right fix. I have another change for operator+ in mind now anyway, which optimizes operator(const string&, char) the same way, and removes the duplication in those five operator+ overloads. > > To fix https://gcc.gnu.org/PR106735 I'm just going to revert it for > now, and revisit in the morning.