[PATCH 1/2] ipa-cp: only tweak clone incoming edge counts when ipa_p ()
Kugan Vivekanandarajah <[email protected]>
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <[email protected]> |
Fixes ICE in include/c++/16.0.1/bits/stl_tree.h:2801:5 during IPA inline:
internal compiler error: verify_cgraph_node failed
#0 internal_error(char const*, ...)
.../gcc/diagnostic-global-context.cc:787
#1 cgraph_node::verify_node()
.../gcc/cgraph.cc:4499
#2 symtab_node::verify()
.../gcc/symtab.cc:1377
#3 optimize_inline_calls(tree_node*)
.../gcc/tree-inline.cc:5677
#4 inline_transform(cgraph_node*)
.../gcc/ipa-inline-transform.cc:871
#5 execute_one_ipa_transform_pass
.../gcc/passes.cc:2336
#6 execute_all_ipa_transforms(bool)
.../gcc/passes.cc:2400
#7 cgraph_node::expand()
.../gcc/cgraphunit.cc:1867
#8 cgraph_node::expand()
.../gcc/cgraphunit.cc:1827
#9 expand_all_functions
.../gcc/cgraphunit.cc:2057
#10 symbol_table::compile()
.../gcc/cgraphunit.cc:2435
#11 lto_main()
.../gcc/lto/lto.cc:694
adjust_clone_incoming_counts: only combine or increment incoming edge
counts when the edge count is IPA-visible (ipa_p ()), following the same
rule already used in update_counts_for_self_gen_clones when scaling
recursive clone edges (commit 8c6b6adce45a550c52dc35e3df4e0c477f5404fa).
Rewriting non-IPA edge counts leaves gimple BB frequencies inconsistent
with the call graph and trips verify_cgraph_node.
gcc/ChangeLog:
2026-04-16 Kugan Vivekanandarajah <[email protected]>
* ipa-cp.cc (adjust_clone_incoming_counts): Adjust counts only when
ipa quality.
Regression tested on aarch64-linux-gnu with no new regressions.
Signed-off-by: Kugan Vivekanandarajah <[email protected]>
---
gcc/ipa-cp.cc | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
index d5d9709e118..019bec5aedf 100644
--- a/gcc/ipa-cp.cc
+++ b/gcc/ipa-cp.cc
@@ -4620,24 +4620,34 @@ adjust_clone_incoming_counts (cgraph_node *node,
if (cs->caller->thunk)
{
adjust_clone_incoming_counts (cs->caller, desc);
- profile_count sum = profile_count::zero ();
- for (cgraph_edge *e = cs->caller->callers; e; e = e->next_caller)
- if (e->count.initialized_p ())
- sum += e->count.ipa ();
- cs->count = cs->count.combine_with_ipa_count (sum);
+ /* Same rationale as commit 8c6b6adce45a550c52dc35e3df4e0c477f5404fa
+ for scaling recursive edges in update_counts_for_self_gen_clones:
+ adjusting non-IPA edge counts here does not update matching gimple
+ BB frequencies and breaks verify_cgraph_node. */
+ if (cs->count.ipa_p ())
+ {
+ profile_count sum = profile_count::zero ();
+ for (cgraph_edge *e = cs->caller->callers; e; e = e->next_caller)
+ if (e->count.initialized_p ())
+ sum += e->count.ipa ();
+ cs->count = cs->count.combine_with_ipa_count (sum);
+ }
}
else if (!desc->processed_edges->contains (cs)
&& cs->caller->clone_of == desc->orig
&& cs->count.compatible_p (desc->count))
{
- cs->count += desc->count;
- if (dump_file)
+ if (cs->count.ipa_p ())
{
- fprintf (dump_file, " Adjusted count of an incoming edge of "
- "a clone %s -> %s to ", cs->caller->dump_name (),
- cs->callee->dump_name ());
- cs->count.dump (dump_file);
- fprintf (dump_file, "\n");
+ cs->count += desc->count;
+ if (dump_file)
+ {
+ fprintf (dump_file, " Adjusted count of an incoming edge "
+ "of a clone %s -> %s to ", cs->caller->dump_name (),
+ cs->callee->dump_name ());
+ cs->count.dump (dump_file);
+ fprintf (dump_file, "\n");
+ }
}
}
}
--
2.34.1