[gcc r16-3547] Do not auto-enable loop optimizations with AutoFDO
Jan Hubicka
hubicka@gcc.gnu.org
Wed Sep 3 15:56:27 GMT 2025
https://gcc.gnu.org/g:2c4fcab25fc0362359c87ab955b24c54aa41b46c
commit r16-3547-g2c4fcab25fc0362359c87ab955b24c54aa41b46c
Author: Jan Hubicka <hubicka@ucw.cz>
Date: Wed Sep 3 17:55:54 2025 +0200
Do not auto-enable loop optimizations with AutoFDO
With -O2 we automatically enable several loop optimizations with -fprofile-use.
The rationale is that those optimizations at -O3 only mainly since they may
hurt performance or not pay back in code size when used blindly on all loops.
Profile feedback gives us data on number of iterations which is used by heuristics
controlling those optimizations.
Currently auto-FDO is not that good on determining number of iterations so I think we
do not want to enable them until we can prove that those are useful.
This is affecting primarily -O2 codegen.
Theoretically auto-FdO with lbr can be pretty good on estimating # of
iterations, but to make it useful we will need to implement multiplicity for
discriminators at least.
Bootstrapped/regtested x86_64-linux, comitted.
gcc/ChangeLog:
* opts.cc (enable_fdo_optimizations): Do not auto-enabele loop
optimizations with AutoFDO.
Diff:
---
gcc/opts.cc | 45 ++++++++++++++++++++++++++++-----------------
1 file changed, 28 insertions(+), 17 deletions(-)
diff --git a/gcc/opts.cc b/gcc/opts.cc
index 3ab993aea573..baba08488d4a 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -2097,11 +2097,10 @@ enable_fdo_optimizations (struct gcc_options *opts,
SET_OPTION_IF_UNSET (opts, opts_set, flag_branch_probabilities, value);
SET_OPTION_IF_UNSET (opts, opts_set, flag_profile_values, value);
}
- SET_OPTION_IF_UNSET (opts, opts_set, flag_unroll_loops, value);
- SET_OPTION_IF_UNSET (opts, opts_set, flag_peel_loops, value);
- SET_OPTION_IF_UNSET (opts, opts_set, flag_tracer, value);
SET_OPTION_IF_UNSET (opts, opts_set, flag_value_profile_transformations,
value);
+
+ /* Enable IPA optimizatins that makes effective use of profile data. */
SET_OPTION_IF_UNSET (opts, opts_set, flag_inline_functions, value);
SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_cp, value);
if (value)
@@ -2109,21 +2108,33 @@ enable_fdo_optimizations (struct gcc_options *opts,
SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_cp_clone, 1);
SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_bit_cp, 1);
}
- SET_OPTION_IF_UNSET (opts, opts_set, flag_predictive_commoning, value);
- SET_OPTION_IF_UNSET (opts, opts_set, flag_split_loops, value);
- SET_OPTION_IF_UNSET (opts, opts_set, flag_unswitch_loops, value);
+
SET_OPTION_IF_UNSET (opts, opts_set, flag_gcse_after_reload, value);
- SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_vectorize, value);
- SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_slp_vectorize, value);
- SET_OPTION_IF_UNSET (opts, opts_set, flag_version_loops_for_strides, value);
- SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
- VECT_COST_MODEL_DYNAMIC);
- SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_distribute_patterns,
- value);
- SET_OPTION_IF_UNSET (opts, opts_set, flag_loop_interchange, value);
- SET_OPTION_IF_UNSET (opts, opts_set, flag_unroll_jam, value);
- SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_distribution, value);
- SET_OPTION_IF_UNSET (opts, opts_set, flag_optimize_crc, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_tracer, value);
+
+ /* Loop optimizations uses profile feedback to determine their profitability
+ and thus it makes sense to enable them by default even at -O2.
+ Auto-profile, in its current form, is not very good on determining
+ iteration counts and thus only real profile feedback is used. */
+ if (!autofdo)
+ {
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_unroll_loops, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_peel_loops, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_predictive_commoning, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_split_loops, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_unswitch_loops, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_vectorize, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_slp_vectorize, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_version_loops_for_strides, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
+ VECT_COST_MODEL_DYNAMIC);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_distribute_patterns,
+ value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_loop_interchange, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_unroll_jam, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_distribution, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_optimize_crc, value);
+ }
}
/* -f{,no-}sanitize{,-recover}= suboptions. */
More information about the Gcc-cvs
mailing list