From: Martin Jambor Date: Fri, 16 Jan 2026 11:04:23 +0000 (+0100) Subject: ipa-cp: Fix devirt bonus for targets that cannot be inlined X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54d98b104420363d8109aee1bb275f4567c756f0;p=thirdparty%2Fgcc.git ipa-cp: Fix devirt bonus for targets that cannot be inlined PR 123412 has been filed because since commit r16-3990-gad3fb999a1b568 (Jan Hubicka: Improve ipa-cp devirtualization costing), there is accidentally zero devirtualization bonus for functions which cannot be inlined. This has resulted in g++.dg/ipa/devirt-2.C failing since it has been pushed because the required function is not cloned even with --param max-devirt-targets=1. The intention was that we do get at least some small benefit boost and so this patch adds an addition of the indirect edge frequency once before the early continue statements. gcc/ChangeLog: 2026-01-14 Martin Jambor PR ipa/123412 * ipa-cp.cc (devirtualization_time_bonus): Do add the indirect edge frequency at least once even for targets which cannot be inlined. --- diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index 8e2aafc7923..3fd68b5aea0 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -3355,7 +3355,7 @@ devirtualization_time_bonus (struct cgraph_node *node, continue; /* Only bare minimum benefit for clearly un-inlineable targets. */ - int savings = 1; + res = res + ie->combined_sreal_frequency (); callee = cgraph_node::get (target); if (!callee || !callee->definition) continue; @@ -3366,18 +3366,21 @@ devirtualization_time_bonus (struct cgraph_node *node, if (!isummary || !isummary->inlinable) continue; + int savings = 0; int size = ipa_size_summaries->get (callee)->size; /* FIXME: The values below need re-considering and perhaps also integrating into the cost metrics, at lest in some very basic way. */ int max_inline_insns_auto = opt_for_fn (callee->decl, param_max_inline_insns_auto); if (size <= max_inline_insns_auto / 4) - savings += 31 / ((int)speculative + 1); + savings = 31 / ((int)speculative + 1); else if (size <= max_inline_insns_auto / 2) - savings += 15 / ((int)speculative + 1); + savings = 15 / ((int)speculative + 1); else if (size <= max_inline_insns_auto || DECL_DECLARED_INLINE_P (callee->decl)) - savings += 7 / ((int)speculative + 1); + savings = 7 / ((int)speculative + 1); + else + continue; res = res + ie->combined_sreal_frequency () * (sreal) savings; }