From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id 2CE143858D28 for ; Tue, 30 Aug 2022 13:19:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2CE143858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ispras.ru Received: from [10.10.3.121] (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTPS id B7EDC40737AA; Tue, 30 Aug 2022 13:19:11 +0000 (UTC) Date: Tue, 30 Aug 2022 16:19:11 +0300 (MSK) From: Alexander Monakov To: Martin Jambor cc: gcc-patches@gcc.gnu.org, Jan Hubicka , Artem Klimov Subject: Re: [PATCH v2] ipa-visibility: Optimize TLS access [PR99619] In-Reply-To: Message-ID: <8e8fca33-3a17-ed4e-c1f8-dc2956d6f0bc@ispras.ru> References: <20220707155341.5884-1-amonakov@ispras.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,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 Tue, 30 Aug 2022, Martin Jambor wrote: > There is still the optimize attribute so in fact no, even in non-LTO > mode if there is no current function, you cannot trust the "global" > "optimize" thing. > > Ideally we would assert that no "analysis" phase of an IPA pass reads > the global optimization flags, so please don't add new places where we > do. > > You can either add a parameter to decl_default_tls_model to tell it > what context it is called from and IMHO it would also be acceptable to > check whether we have a non-NULL cfun and decide based on that (but here > I only hope it is not something others might object to). I see, thank you for explaining the issue, and sorry if I was a bit stubborn. Does the attached patch (incremental change below) look better? It no longer has the 'shortcut' where iterating over referrers is avoided for the common case of plain 'gcc -O2' and no 'optimize' attributes, but fortunately TLS variables are not so numerous to make chasing that worthwhile. --- a/gcc/varasm.cc +++ b/gcc/varasm.cc @@ -6703,8 +6703,8 @@ have_optimized_refs (struct symtab_node *symbol) static bool optimize_dyn_tls_for_decl_p (const_tree decl) { - if (optimize) - return true; + if (cfun) + return optimize; return symtab->state >= IPA && have_optimized_refs (symtab_node::get (decl)); } Alexander