https://gcc.gnu.org/g:daf383afa746e02e4756c715a8cedafbb61d6547
commit r17-5632-gdaf383afa746e02e4756c715a8cedafbb61d6547 Author: Josef Melcr <[email protected]> Date: Wed Sep 16 13:52:24 2026 +0200 ipa: Help passes make decisions about assume bodies Assume bodies don't fit in most of the heuristics of the IPA passes. They are usually not profitable, but since they are purely an optimization tool and don't make it into the binary anyway , we want to make the most of them. This patch introduces several bypasses for checks which would prevent their optimizations, be it cloning or parameter splitting. gcc/ChangeLog: * ipa-cp.cc (good_cloning_opportunity_p): Special case assume functions. * ipa-sra.cc (adjust_parameter_descriptions): Likewise. Signed-off-by: Josef Melcr <[email protected]> Diff: --- gcc/ipa-cp.cc | 26 +++++++++++++++++++++++--- gcc/ipa-sra.cc | 12 +++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index 4ae6c7516ef6..76d3b0decda6 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -3459,15 +3459,35 @@ good_cloning_opportunity_p (struct cgraph_node *node, sreal time_benefit, gcc_assert (count_sum.ipa () == count_sum); if (count_sum.quality () == AFDO) count_sum = count_sum.force_nonzero (); + if (!opt_for_fn (node->decl, flag_ipa_cp_clone)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + " good_cloning_opportunity_p (time: %g, " + "size: %i): Cloning is prohibited.\n", + time_benefit.to_double (), size_cost); + return false; + } + + /* Assume bodies don't make it into the final binary, so they have no real + size. Special case them, as cloning them is always a good idea. */ + if (node->assume_function) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, " good_cloning_opportunity_p: Always clone " + "assume body functions.\n"); + return true; + } + if (time_benefit == 0 - || !opt_for_fn (node->decl, flag_ipa_cp_clone) /* If there is no call which was executed in profiling or where profile is missing, we do not want to clone. */ || (!called_without_ipa_profile && !count_sum.nonzero_p ())) { if (dump_file && (dump_flags & TDF_DETAILS)) - fprintf (dump_file, " good_cloning_opportunity_p (time: %g, " - "size: %i): Definitely not good or prohibited.\n", + fprintf (dump_file, + " good_cloning_opportunity_p (time: %g, " + "size: %i): Definitely not good.\n", time_benefit.to_double (), size_cost); return false; } diff --git a/gcc/ipa-sra.cc b/gcc/ipa-sra.cc index a147d7111440..776c4675397d 100644 --- a/gcc/ipa-sra.cc +++ b/gcc/ipa-sra.cc @@ -2575,8 +2575,11 @@ process_scan_results (cgraph_node *node, struct function *fun, * param_size_limit); } - if (nonarg_acc_size > optimistic_limit - || (!desc->by_ref && nonarg_acc_size == param_size_limit)) + /* Assume functions have no real replacements, no calls to them will make + it into the binary, so limits don't matter. */ + if (!node->assume_function + && (nonarg_acc_size > optimistic_limit + || (!desc->by_ref && nonarg_acc_size == param_size_limit))) { disqualify_split_candidate (desc, "Would result into a too big set " "of replacements even in best " @@ -4462,7 +4465,10 @@ adjust_parameter_descriptions (cgraph_node *node, isra_func_summary *ifs) param_ipa_sra_ptrwrap_growth_factor); desc->param_size_limit = extra_factor * desc->param_size_limit; } - if (size_would_violate_limit_p (desc, desc->size_reached)) + /* Don't disqualify assume bodies, as they don't make into the final + binary anyway. */ + if (!node->assume_function + && size_would_violate_limit_p (desc, desc->size_reached)) desc->split_candidate = false; }
