Hi,

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.

The testcase g++.dg/ipa/devirt-2.C passes with this patch.  Bootstrap
and full testsuite run on x86_64-linux is under way.  OK for master if
it passes?

Thanks,

Martin


gcc/ChangeLog:

2026-01-14  Martin Jambor  <[email protected]>

        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 | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

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;
     }
 
-- 
2.52.0

Reply via email to