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.129.124]) by sourceware.org (Postfix) with ESMTPS id 1E05F3858C41 for ; Tue, 23 Apr 2024 03:14:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E05F3858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1E05F3858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713842080; cv=none; b=dwMb9pOrK/osDwgrsoqTk++ErsV5t/O/VKnf1bs8vd9zvRBxMfWm0TXnJyjTthCGI07FjRPBNRU8NqUmLVAKImEw/MsvZ4FIboJtXkA9C6ETKLyPFp8TAZwkJSQpRCmjz4WhRRwLQgsTKtn0lOEdUsLdvKSyB3k4e9fbdRbYrVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713842080; c=relaxed/simple; bh=02jwLhEXMTGHftcJOESMJhUqOyk2ShPeMsxDA4+h7Mk=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=k/dxX330OavC3eAps3OYQ4mk1O26RymHYEbC9TBIGeypfz7lrbM1w4b4OkAHgHvCSbtSgqBG8Tag6AumgWslvoZz5xNTAElIM4ZJXnbH4oBYqAPgVo88+8r9UwinfounOpeFKb8S5Lk7OOkuXAvD9mxc4g2E0gPOjEFKdjVGo2o= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713842078; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1MTZKGVs4Sa5QvaHu/IUiGw2pbXIfpT/+7TXGFsElSU=; b=AdRu2R1VTHp5vcipODahzNwRk+S8n+muPK3sKtjb+VGuG0OjmG+ilGqfCQWCHPtmQsn0GR IutVA4ksvTuEvKGYYCjuSEqwGAMdzvHH74IT1ATw3/KKjrYsS49bhil5lL5lL8A3ebx5I5 YxaWwXj53KZAFB/gpfLb+Ua4pJ69BrY= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-447-1rVrDbZXNY65dN98i5HUfg-1; Mon, 22 Apr 2024 23:14:37 -0400 X-MC-Unique: 1rVrDbZXNY65dN98i5HUfg-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-78f08178393so1152682785a.1 for ; Mon, 22 Apr 2024 20:14:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713842077; x=1714446877; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1MTZKGVs4Sa5QvaHu/IUiGw2pbXIfpT/+7TXGFsElSU=; b=P2o7No2+zz7uJ5AIaLWmOUdrNwlxG+sQtvhBFBe7a8TffjYbzb6kkgjqfMwMTJ/d/l 4giyE7NS2uh8zD8nRNEb4cLakMQjH8JG4DRucdV0CmI4qC8lEI1rQZz3irl8FdSvQHN5 zXz2fJSXablCpy+PHDBFq6u4sx+jiwPLFbhlOG9QqRj/x6QTT6SUhl0Q5KTEhD9iBzk8 j31U4ENDoniJc8Q6AtCheK6YlIyTFCBRXjtyfhumItxeW7gYG4+l0llLQYvCODH9W9vt NNiVtd+toan2s+I6MJZy+lBrGYM++azz4LtJ1Uph5HDFqkkFywyRmLH2tfi6B/Aca/Tu A/yg== X-Gm-Message-State: AOJu0Yypq+guT1Hdv6raJtdBc5TgS6BOl0dTnC/+a2qUzDsI3w6rkpFU foTTzHnDB1nPRF9GgENCDZHXad5lDeMQdzKRqz6V2z/udZlvTA582ldqMWUJZLtWxuj4lDr9wdN UDRRcQRHNaBQbSNf8AjPzu5671V3zUj6BxXwTBspRqt2Yl8cFZb9f1mE= X-Received: by 2002:a05:620a:568a:b0:78f:13d9:9a87 with SMTP id wg10-20020a05620a568a00b0078f13d99a87mr2151754qkn.22.1713842076998; Mon, 22 Apr 2024 20:14:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVyK0unBgMDH3oUQ1PgSoT83JYSLTDYXPoGNP8INAkCwqLZ0ZqCtbRX+lS6h9y46IUDmWJAA== X-Received: by 2002:a05:620a:568a:b0:78f:13d9:9a87 with SMTP id wg10-20020a05620a568a00b0078f13d99a87mr2151743qkn.22.1713842076680; Mon, 22 Apr 2024 20:14:36 -0700 (PDT) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id xx10-20020a05620a5d8a00b0078d65c88a58sm4887721qkn.41.2024.04.22.20.14.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Apr 2024 20:14:36 -0700 (PDT) Message-ID: <5fe9db40-4bff-4be4-a434-6509133f26e3@redhat.com> Date: Mon, 22 Apr 2024 23:14:35 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++, v2: Retry the aliasing of base/complete cdtor optimization at import_export_decl time [PR113208] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org, Jan Hubicka , Richard Biener , Patrick Palka References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP 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 4/22/24 08:42, Jakub Jelinek wrote: > On Wed, Apr 17, 2024 at 09:42:47AM +0200, Jakub Jelinek wrote: >> When expand_or_defer_fn is called at_eof time, it calls import_export_decl >> and then maybe_clone_body, which uses DECL_ONE_ONLY and comdat name in a >> couple of places to try to optimize cdtors which are known to have the >> same body by making the complete cdtor an alias to base cdtor (and in >> that case also uses *[CD]5* as comdat group name instead of the normal >> comdat group names specific to each mangled name). >> Now, this optimization depends on DECL_ONE_ONLY and DECL_INTERFACE_KNOWN, >> maybe_clone_body and can_alias_cdtor use: >> if (DECL_ONE_ONLY (fn)) >> cgraph_node::get_create (clone)->set_comdat_group (cxx_comdat_group (clone)); >> ... >> bool can_alias = can_alias_cdtor (fn); >> ... >> /* Tell cgraph if both ctors or both dtors are known to have >> the same body. */ >> if (can_alias >> && fns[0] >> && idx == 1 >> && cgraph_node::get_create (fns[0])->create_same_body_alias >> (clone, fns[0])) >> { >> alias = true; >> if (DECL_ONE_ONLY (fns[0])) >> { >> /* For comdat base and complete cdtors put them >> into the same, *[CD]5* comdat group instead of >> *[CD][12]*. */ >> comdat_group = cdtor_comdat_group (fns[1], fns[0]); >> cgraph_node::get_create (fns[0])->set_comdat_group (comdat_group); >> if (symtab_node::get (clone)->same_comdat_group) >> symtab_node::get (clone)->remove_from_same_comdat_group (); >> symtab_node::get (clone)->add_to_same_comdat_group >> (symtab_node::get (fns[0])); >> } >> } >> and >> /* Don't use aliases for weak/linkonce definitions unless we can put both >> symbols in the same COMDAT group. */ >> return (DECL_INTERFACE_KNOWN (fn) >> && (SUPPORTS_ONE_ONLY || !DECL_WEAK (fn)) >> && (!DECL_ONE_ONLY (fn) >> || (HAVE_COMDAT_GROUP && DECL_WEAK (fn)))); >> The following testcase regressed with Marek's r14-5979 change, >> when pr113208_0.C is compiled where the ctor is marked constexpr, >> we no longer perform this optimization, where >> _ZN6vectorI12QualityValueEC2ERKS1_ was emitted in the >> _ZN6vectorI12QualityValueEC5ERKS1_ comdat group and >> _ZN6vectorI12QualityValueEC1ERKS1_ was made an alias to it, >> instead we emit _ZN6vectorI12QualityValueEC2ERKS1_ in >> _ZN6vectorI12QualityValueEC2ERKS1_ comdat group and the same >> content _ZN6vectorI12QualityValueEC1ERKS1_ as separate symbol in >> _ZN6vectorI12QualityValueEC1ERKS1_ comdat group. This seems like an ABI bug that could use a non-LTO testcase. >> Now, the linker seems to somehow cope with that, eventhough it >> probably keeps both copies of the ctor, but seems LTO can't cope >> with that and Honza doesn't know what it should do in that case >> (linker decides that the prevailing symbol is >> _ZN6vectorI12QualityValueEC2ERKS1_ (from the >> _ZN6vectorI12QualityValueEC2ERKS1_ comdat group) and >> _ZN6vectorI12QualityValueEC1ERKS1_ alias (from the other TU, >> from _ZN6vectorI12QualityValueEC5ERKS1_ comdat group)). >> >> Note, the case where some constructor is marked constexpr in one >> TU and not in another one happens pretty often in libstdc++ when >> one mixes -std= flags used to compile different compilation units. >> >> The reason the optimization doesn't trigger when the constructor is >> constexpr is that expand_or_defer_fn is called in that case much earlier >> than when it is not constexpr; in the former case it is called when we >> try to constant evaluate that constructor. But DECL_INTERFACE_KNOWN >> is false in that case and comdat_linkage hasn't been called either >> (I think it is desirable, because comdat group is stored in the cgraph >> node and am not sure it is a good idea to create cgraph nodes for >> something that might not be needed later on at all), so maybe_clone_body >> clones the bodies, but doesn't make them as aliases. Hmm, cloning the bodies and then discarding them later seems like more extra work than creating the cgraph nodes. Jason