This modifies the decision making stage of IPA-CP in two ways:
Previously, local effects of the cloning were estimated only for the
constant that was being considered, even though the calls which bring
it also carry other constants. With this patch, all knowsn constants
for the given subset of caller edges are considered and the heuritics
should therefore have more information and generally work better.
Also, when evaluating the opportunities for a given node, IPA-CP
previously just iterate over the parameters starting with the first
one and if any opportunity looked profitable, it was carried out and
associated calling edges were redirected, even if this precludes some
even better opportunity. The patch tries to mitigate this by first
using the initial estimates to sort all cloning candidates and then
iterate in that order.
The one difference from the version I posted before is that I have
extended the checking assert making sure the value we clone for is
indeed used to also work for non-aggregate constants and polymorphic
contexts.
gcc/ChangeLog:
2025-12-01 Martin Jambor <mjambor@suse.cz>
* ipa-cp.cc (good_cloning_opportunity_p): Dump a message when
bailing out early too.
(find_more_scalar_values_for_callers_subset): Rename to
find_scalar_values_for_callers_subset, collect constants regardless of
what is already in the vector. Remove dumping.
(find_more_contexts_for_caller_subset): Rename to
find_contexts_for_caller_subset, collect contexts regardless of what
is already in the vector. Remove dumping.
(find_aggregate_values_for_callers_subset): Rename to
find_aggregate_values_for_callers_subset_gc, implement using new
functions.
(find_aggregate_values_for_callers_subset_1): New function.
(find_aggregate_values_for_callers_subset): Likewise.
(copy_known_vectors_add_val): Removed.
(dump_reestimation_message): New function.
(decide_about_value): Remove formal parameter avals, compute it
independently, and use it to estimate local cloning effects.
(struct cloning_opportunity_ranking): New type.
(compare_cloning_opportunities): New function.
(cloning_opportunity_ranking_evaluation): Likewise.
(decide_whether_version_node): Pre-sort candidates for cloning before
really evaluating them. Calculate context independent values only
when considering versioning for all contexts.
(ipcp_val_agg_replacement_ok_p): Renamed to
ipcp_val_replacement_ok_p, check also non-aggregate values.