On Mon, Sep 06, 2021 at 11:18:47AM +0200, Richard Biener wrote: > On Mon, Sep 6, 2021 at 10:47 AM liuhongt via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: > > > > Hi: > > As discussed in [1], most of (currently unopposed) targets want > > auto-vectorization at O2, and IMHO now would be a good time to enable O2 > > vectorization for GCC trunk, so it would leave enough time to expose > > related issues and fix them. > > > > Bootstrapped and regtested on x86_64-linux-gnu{-m32,} > > Ok for trunk? > > It changes the cost model used when the user specifices > -O2 -ftree-vectorize which used 'cheap' before but now sticks to > 'very-cheap'. I guess adjusting the cost model in process_options > might be possible when any(?) of the vectorizer flags were set > explicitly?
process_options would mean it affects only the command line and not __attribute__((optimize ("O2", "ftree-vectorize"))) etc. So, shouldn't it be instead done in default_options_optimization, somewhere among the if (openacc_mode) SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_pta, true); /* Track fields in field-sensitive alias analysis. */ if (opt2) SET_OPTION_IF_UNSET (opts, opts_set, param_max_fields_for_field_sensitive, 100); if (opts->x_optimize_size) /* We want to crossjump as much as possible. */ SET_OPTION_IF_UNSET (opts, opts_set, param_min_crossjump_insns, 1); /* Restrict the amount of work combine does at -Og while retaining most of its useful transforms. */ if (opts->x_optimize_debug) SET_OPTION_IF_UNSET (opts, opts_set, param_max_combine_insns, 2); in there? Like: /* Use -fvect-cost-model=cheap instead of -fvect-cost-mode=very-cheap by default with explicit -ftree-{loop,slp}-vectorize. */ if (opts->x_optimize == 2 && (opts_set->x_ftree_loop_vectorize || opts_set->x_ftree_slp_vectorize)) SET_OPTION_IF_UNSET (opts, opts_set, fvect_cost_model_, VECT_COST_MODEL_CHEAP); Though, unsure if that will work with -O2 -ftree-vectorize which is an option without flag with EnabledBy on the other two options. Also, is: + { OPT_LEVELS_2_PLUS, OPT_ftree_loop_vectorize, NULL, 1 }, + { OPT_LEVELS_2_PLUS, OPT_ftree_slp_vectorize, NULL, 1 }, what we really want, isn't that instead: + { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_ftree_loop_vectorize, NULL, 1 }, + { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_ftree_slp_vectorize, NULL, 1 }, ? I mean, for -Os vectorization even in very-cheap model I'd think it usually enlarges code size, and for -Og it is seriously harmful for debugging experience, especially when DWARF <= 5 doesn't have anything that would help debugging vectorized loops. Jakub