From patchwork Thu Nov 11 13:27:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 47463 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F2C603857C53 for ; Thu, 11 Nov 2021 13:28:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F2C603857C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636637306; bh=o2/kZJyZ/GROd4WLMjWZJbs4mDxi+lBFftUTPYOL+w8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=D9eNbt1hUpUhFXX7TQmR6i1uCjtP8SKhcNqgAaAOl4kNwqNmNBD6Ors7QfwsAEwWh dDNyPodmBSRvm3gGwn8lyM+WDw0gG4Jg6x/ikTPPo5G6LH3QEWZcRsrstjbDN9rcLH Bgvbvi/+r4DmjJF3DRJSThtqCCRKMBs4Y2Ohj96I= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 3367E385840A for ; Thu, 11 Nov 2021 13:27:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3367E385840A Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 2E2F82827E7; Thu, 11 Nov 2021 14:27:56 +0100 (CET) Date: Thu, 11 Nov 2021 14:27:56 +0100 To: gcc-patches@gcc.gnu.org Subject: Fix noreturn discovery Message-ID: <20211111132756.GE17431@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, this patch fixes ipa-pure-const handling of noreturn flags. It is not safe to set it for interposable symbols and we should also set it for aliases (just like we do for other flags). This patch merely copies other flag handling and implements it here. Bootstrapped/regtested x86_64-linux, will commit it shortly. Honza gcc/ChangeLog: 2021-11-11 Jan Hubicka * cgraph.c (set_noreturn_flag_1): New function. (cgraph_node::set_noreturn_flag): New member function * cgraph.h (cgraph_node::set_noreturn_flags): Declare. * ipa-pure-const.c (pass_local_pure_const::execute): Use it. diff --git a/gcc/cgraph.c b/gcc/cgraph.c index c67d300e7a4..466b66d5ba5 100644 --- a/gcc/cgraph.c +++ b/gcc/cgraph.c @@ -2614,6 +2614,53 @@ cgraph_node::set_malloc_flag (bool malloc_p) return changed; } +/* Worker to set noreturng flag. */ +static void +set_noreturn_flag_1 (cgraph_node *node, bool noreturn_p, bool *changed) +{ + if (noreturn_p && !TREE_THIS_VOLATILE (node->decl)) + { + TREE_THIS_VOLATILE (node->decl) = true; + *changed = true; + } + + ipa_ref *ref; + FOR_EACH_ALIAS (node, ref) + { + cgraph_node *alias = dyn_cast (ref->referring); + if (!noreturn_p || alias->get_availability () > AVAIL_INTERPOSABLE) + set_noreturn_flag_1 (alias, noreturn_p, changed); + } + + for (cgraph_edge *e = node->callers; e; e = e->next_caller) + if (e->caller->thunk + && (!noreturn_p || e->caller->get_availability () > AVAIL_INTERPOSABLE)) + set_noreturn_flag_1 (e->caller, noreturn_p, changed); +} + +/* Set TREE_THIS_VOLATILE on NODE's decl and on NODE's aliases if any. */ + +bool +cgraph_node::set_noreturn_flag (bool noreturn_p) +{ + bool changed = false; + + if (!noreturn_p || get_availability () > AVAIL_INTERPOSABLE) + set_noreturn_flag_1 (this, noreturn_p, &changed); + else + { + ipa_ref *ref; + + FOR_EACH_ALIAS (this, ref) + { + cgraph_node *alias = dyn_cast (ref->referring); + if (!noreturn_p || alias->get_availability () > AVAIL_INTERPOSABLE) + set_noreturn_flag_1 (alias, noreturn_p, &changed); + } + } + return changed; +} + /* Worker to set_const_flag. */ static void diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 0a1f7c8960e..e42e305cdb6 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -1167,6 +1167,10 @@ struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node if any. */ bool set_malloc_flag (bool malloc_p); + /* SET TREE_THIS_VOLATILE on cgraph_node's decl and on aliases of the node + if any. */ + bool set_noreturn_flag (bool noreturn_p); + /* If SET_CONST is true, mark function, aliases and thunks to be ECF_CONST. If SET_CONST if false, clear the flag. diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c index 505ed4f8a3b..84a028bcf8e 100644 --- a/gcc/ipa-pure-const.c +++ b/gcc/ipa-pure-const.c @@ -2132,11 +2132,10 @@ pass_local_pure_const::execute (function *fun) current_function_name ()); /* Update declaration and reduce profile to executed once. */ - TREE_THIS_VOLATILE (current_function_decl) = 1; + if (cgraph_node::get (current_function_decl)->set_noreturn_flag (true)) + changed = true; if (node->frequency > NODE_FREQUENCY_EXECUTED_ONCE) node->frequency = NODE_FREQUENCY_EXECUTED_ONCE; - - changed = true; } switch (l->pure_const_state)