From patchwork Mon Jul 22 21:05:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 94350 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 AB732386101A for ; Mon, 22 Jul 2024 21:06:36 +0000 (GMT) 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 501623860C3F for ; Mon, 22 Jul 2024 21:05:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 501623860C3F Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kam.mff.cuni.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 501623860C3F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.113.20.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721682361; cv=none; b=kZEjzyuG/R+5uU5rfKWpzRU3CGrNcWc99+7mXgJWxaL2N9m8J5j8YG55GjRtdmpU3bAEVCyRi+jbirnYNJqgXLwIMAaJTMfISGE/yHH4oxFOGIORMxlMNg5Hfnl3BYC7p6AUhU9B5Hac8EcLOEvcmNAWTg6jOBboqCPoC/3VPAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721682361; c=relaxed/simple; bh=Q2Z3Qelk9ICOf3zqLZJ3pPcEEEe1P+QgyfGvQDvwtKY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=xAgRLVN+dVFOeqn3PJbHh6ZnsZOPT/BryPr3BRNXhwsUxOWpQpzpPCXnj0qMxzRUi4edzES7vTjClq6ui/D9DnwD+7jVYNcu4ZnIJ7vFTD1d9EHrG8abFYhp1KIIWaskJezqYTh4o0KsoUIBX4X89INJT/vKacIUKe3ZqdfjfCY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id B2C84287928; Mon, 22 Jul 2024 23:05:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1721682356; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=zAgc9ky262awkAEI1MqkKu8NcIqXG86shDwh4C/YoYY=; b=rudwKzXHSucD8fML6GUG9ww7CPAg6FWFJNanqtDYBRs8CfwsBOCXGYo0m5lEQL3MIkmNHu VNDL0jeYLovA7pYY/yxm+O7KIhO7n/bnHyMiHFKffxhxBGrLdoOrHk7MNHqksG1BTeNOVO f7jmi0PnrnHfe/3M2wDZMmtpcnWBQ7k= Date: Mon, 22 Jul 2024 23:05:56 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix handling of ICF_NOVOPS in ipa-modref Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, JMQ_SPF_NEUTRAL, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Hi, As shown in somewhat convoluted testcase, ipa-modref is mistreating ECF_NOVOPS as "having no side effects". This come from time when modref cared only about memory accesses and thus it was possible to shortcut on it. This patch removes (hopefully) all those bad shortcuts. Bootstrapped/regtested x86_64-linux, comitted. gcc/ChangeLog: PR ipa/109985 * ipa-modref.cc (modref_summary::useful_p): Fix handling of ECF_NOVOPS. (modref_access_analysis::process_fnspec): Likevise. (modref_access_analysis::analyze_call): Likevise. (propagate_unknown_call): Likevise. (modref_propagate_in_scc): Likevise. (modref_propagate_flags_in_scc): Likewise. (ipa_merge_modref_summary_after_inlining): Likewise. diff --git a/gcc/ipa-modref.cc b/gcc/ipa-modref.cc index 53a2e35133d..f6a758b5f42 100644 --- a/gcc/ipa-modref.cc +++ b/gcc/ipa-modref.cc @@ -334,7 +334,7 @@ modref_summary::useful_p (int ecf_flags, bool check_flags) if (check_flags && remove_useless_eaf_flags (static_chain_flags, ecf_flags, false)) return true; - if (ecf_flags & (ECF_CONST | ECF_NOVOPS)) + if (ecf_flags & ECF_CONST) return ((!side_effects || !nondeterministic) && (ecf_flags & ECF_LOOPING_CONST_OR_PURE)); if (loads && !loads->every_base) @@ -1263,7 +1263,7 @@ modref_access_analysis::merge_call_side_effects int flags = gimple_call_flags (call); /* Nothing to do for non-looping cont functions. */ - if ((flags & (ECF_CONST | ECF_NOVOPS)) + if ((flags & ECF_CONST) && !(flags & ECF_LOOPING_CONST_OR_PURE)) return false; @@ -1276,7 +1276,7 @@ modref_access_analysis::merge_call_side_effects /* Merge side effects and non-determinism. PURE/CONST flags makes functions deterministic and if there is no LOOPING_CONST_OR_PURE they also have no side effects. */ - if (!(flags & (ECF_CONST | ECF_NOVOPS | ECF_PURE)) + if (!(flags & (ECF_CONST | ECF_PURE)) || (flags & ECF_LOOPING_CONST_OR_PURE)) { if (!m_summary->side_effects && callee_summary->side_effects) @@ -1465,7 +1465,7 @@ modref_access_analysis::process_fnspec (gcall *call) /* PURE/CONST flags makes functions deterministic and if there is no LOOPING_CONST_OR_PURE they also have no side effects. */ - if (!(flags & (ECF_CONST | ECF_NOVOPS | ECF_PURE)) + if (!(flags & (ECF_CONST | ECF_PURE)) || (flags & ECF_LOOPING_CONST_OR_PURE) || (cfun->can_throw_non_call_exceptions && stmt_could_throw_p (cfun, call))) @@ -1604,12 +1604,12 @@ modref_access_analysis::analyze_call (gcall *stmt) print_gimple_stmt (dump_file, stmt, 0); } - if ((flags & (ECF_CONST | ECF_NOVOPS)) + if ((flags & ECF_CONST) && !(flags & ECF_LOOPING_CONST_OR_PURE)) { if (dump_file) fprintf (dump_file, - " - ECF_CONST | ECF_NOVOPS, ignoring all stores and all loads " + " - ECF_CONST, ignoring all stores and all loads " "except for args.\n"); return; } @@ -1624,7 +1624,13 @@ modref_access_analysis::analyze_call (gcall *stmt) if (dump_file) fprintf (dump_file, gimple_call_internal_p (stmt) ? " - Internal call" : " - Indirect call.\n"); - process_fnspec (stmt); + if (flags & ECF_NOVOPS) + { + set_side_effects (); + set_nondeterministic (); + } + else + process_fnspec (stmt); return; } /* We only need to handle internal calls in IPA mode. */ @@ -4568,7 +4574,7 @@ propagate_unknown_call (cgraph_node *node, return changed; } - if (!(ecf_flags & (ECF_CONST | ECF_NOVOPS | ECF_PURE)) + if (!(ecf_flags & (ECF_CONST | ECF_PURE)) || (ecf_flags & ECF_LOOPING_CONST_OR_PURE) || nontrivial_scc) { @@ -4782,7 +4788,7 @@ modref_propagate_in_scc (cgraph_node *component_node) struct cgraph_node *callee; if (!callee_edge->inline_failed - || ((flags & (ECF_CONST | ECF_NOVOPS)) + || ((flags & ECF_CONST) && !(flags & ECF_LOOPING_CONST_OR_PURE))) continue; @@ -5205,8 +5211,8 @@ modref_propagate_flags_in_scc (cgraph_node *component_node) { escape_summary *sum = escape_summaries->get (e); - if (!sum || (e->indirect_info->ecf_flags - & (ECF_CONST | ECF_NOVOPS))) + if (!sum || ((e->indirect_info->ecf_flags & ECF_CONST) + && !(e->indirect_info->ecf_flags & ECF_LOOPING_CONST_OR_PURE))) continue; changed |= modref_merge_call_site_flags @@ -5231,8 +5237,8 @@ modref_propagate_flags_in_scc (cgraph_node *component_node) modref_summary_lto *callee_summary_lto = NULL; struct cgraph_node *callee; - if (ecf_flags & (ECF_CONST | ECF_NOVOPS) - || !callee_edge->inline_failed) + if ((ecf_flags & ECF_CONST) + && !(ecf_flags & ECF_LOOPING_CONST_OR_PURE)) continue; /* Get the callee and its summary. */ @@ -5330,7 +5336,7 @@ ipa_merge_modref_summary_after_inlining (cgraph_edge *edge) if (!callee_info && to_info) { - if (!(flags & (ECF_CONST | ECF_NOVOPS))) + if (!(flags & (ECF_CONST | ECF_PURE | ECF_NOVOPS))) to_info->loads->collapse (); if (!ignore_stores) to_info->stores->collapse (); @@ -5345,7 +5351,7 @@ ipa_merge_modref_summary_after_inlining (cgraph_edge *edge) /* Merge side effects and non-determinism. PURE/CONST flags makes functions deterministic and if there is no LOOPING_CONST_OR_PURE they also have no side effects. */ - if (!(flags & (ECF_CONST | ECF_NOVOPS | ECF_PURE)) + if (!(flags & (ECF_CONST | ECF_PURE)) || (flags & ECF_LOOPING_CONST_OR_PURE)) { if (to_info)