https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103195
Martin Jambor <jamborm at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jamborm at gcc dot gnu.org --- Comment #7 from Martin Jambor <jamborm at gcc dot gnu.org> --- (In reply to hubicka from comment #6) > Yep, unit growths do not apply for very small units. ipa-cp heuristics > still IMO needs work and be based on relative speedups rather then > absolute for the cutoffs. I'll be happy to discuss how to change IPA-CP cost/benefit estimations (ideally in person next to a whiteboard) but I am somewhat wary of making the heuristics even more similar to the inliner as then all clones will be inlined. Moreover, the problem here is that the constant leads to a loop with known number of iterations, even if it is executed with expected relative frequency of just 0.47, and the extra points it gets for this help it get over the limit. (Would you suggest to scale the bonus by the nonspec time somehow?) The bonus for known loop iteration count is arguably too large. In current master, exchange2_r would be fine with less than half, even in the PGO case. We could also scale the bonus not linearly by estimated frequency of the loop but by... I don't know... its square :-) Looking at the code I also discovered that I (probably) forgot to delete the old addition of a constant bonus and so we scale by 1+frequency rather than the frequency. The simplest way of dealing with this issue would be to have a cut-off frequency for the bonus, like the following which declares all loops that are executed with estimated frequency less than 1/2 as uninteresting: diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index 453e9c93cc3..c9f419c5b34 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -3257,15 +3257,14 @@ hint_time_bonus (cgraph_node *node, const ipa_call_estimates &estimates) { int result = 0; ipa_hints hints = estimates.hints; - if (hints & (INLINE_HINT_loop_iterations | INLINE_HINT_loop_stride)) - result += opt_for_fn (node->decl, param_ipa_cp_loop_hint_bonus); - sreal bonus_for_one = opt_for_fn (node->decl, param_ipa_cp_loop_hint_bonus); - if (hints & INLINE_HINT_loop_iterations) + if (hints & INLINE_HINT_loop_iterations + && estimates.loops_with_known_iterations >= sreal (1, -1)) result += (estimates.loops_with_known_iterations * bonus_for_one).to_int (); - if (hints & INLINE_HINT_loop_stride) + if (hints & INLINE_HINT_loop_stride + && estimates.loops_with_known_strides >= sreal (1, -1)) result += (estimates.loops_with_known_strides * bonus_for_one).to_int (); return result;