This patch add a new flag to let user to tell compiler that the AutoFDO profile is accurate. So the compiler will assume function without any sample is UNLIKELY_EXECUTED. This could save 10%~20% text section size.
Bootstrapped and passed regression test. OK for google-4_8 branch? Thanks, Dehao Index: gcc/common.opt =================================================================== --- gcc/common.opt (revision 203546) +++ gcc/common.opt (working copy) @@ -942,6 +942,10 @@ Common Joined RejectNegative Var(auto_profile_file Use sample profile information for call graph node weights. The profile file is specified in the argument. +fauto-profile-accurate +Common Report Var(flag_auto_profile_accurate) Optimization +Whether to assume the sample profile is accurate. + ; -fcheck-bounds causes gcc to generate array bounds checks. ; For C, C++ and ObjC: defaults off. ; For Java: defaults to on. Index: gcc/predict.c =================================================================== --- gcc/predict.c (revision 203546) +++ gcc/predict.c (working copy) @@ -2866,7 +2866,9 @@ compute_function_frequency (void) || (flag_auto_profile && profile_status == PROFILE_GUESSED)) { int flags = flags_from_decl_or_type (current_function_decl); - if (lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl)) + if (profile_info && flag_auto_profile_accurate) + node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED; + else if (lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl)) != NULL) node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED; else if (lookup_attribute ("hot", DECL_ATTRIBUTES (current_function_decl))