aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Hubicka <hubicka@ucw.cz>2025-09-03 17:55:54 +0200
committerJan Hubicka <hubicka@ucw.cz>2025-09-03 17:56:22 +0200
commit2c4fcab25fc0362359c87ab955b24c54aa41b46c (patch)
treee2fe444c9a71258cc8008234c76461c0c58de259
parent2b8256d0ce18ed4d00868c78f5128d32884ccfa1 (diff)
downloadgcc-2c4fcab25fc0362359c87ab955b24c54aa41b46c.zip
gcc-2c4fcab25fc0362359c87ab955b24c54aa41b46c.tar.gz
gcc-2c4fcab25fc0362359c87ab955b24c54aa41b46c.tar.bz2
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.
-rw-r--r--gcc/opts.cc45
1 files changed, 28 insertions, 17 deletions
diff --git a/gcc/opts.cc b/gcc/opts.cc
index 3ab993a..baba084 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. */