]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ipa-cp: Fix devirt bonus for targets that cannot be inlined
authorMartin Jambor <mjambor@suse.cz>
Fri, 16 Jan 2026 11:04:23 +0000 (12:04 +0100)
committerMartin Jambor <jamborm@gcc.gnu.org>
Fri, 16 Jan 2026 11:06:16 +0000 (12:06 +0100)
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  <mjambor@suse.cz>

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.

gcc/ipa-cp.cc

index 8e2aafc7923e16977147389b56e261279dbfff55..3fd68b5aea0a08a05e4ec2a55b80753c62381291 100644 (file)
@@ -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;
     }