On Mon, May 25, 2020 at 1:10 PM guojiufu <guoji...@linux.ibm.com> wrote: > > Currently option -funroll-loops controls both GIMPLE unroler and > RTL unroller. It is not able to control GIMPLE cunroller and > RTL unroller independently. This patch introducing different flags > to control them seperately, and this also provide more freedom to > tune one of them without affecting another. > > This patch introduces two undocumented flags: -fcomplete-unroll-loops > for GIMPLE cunroll, and -frtl-unroll-loops for RTL unroller. And > these two options are enabled by original -funroll-loops.
I don't like the new -fcomplete-unroll-loops name. It does not match the implementation either (the gate functions of cunroll and cunrolli only check optimize against 2/3), given it just controls whether unrolling can grow code size. > - SET_OPTION_IF_UNSET (opts, opts_set, flag_unroll_loops, value); > + SET_OPTION_IF_UNSET (opts, opts_set, flag_complete_unroll_loops, value); This is also not a no-op change. Since a new flag is not needed to fix the regression please avoid adding -fcomplete-unroll-loops. For -frtl-unroll-loops you should be able to use EnabledBy(funroll-loops) and thus you can simplify option handling accordingly. Thanks, Richard. > Bootstrap and regtest pass on powerpc64le, is this ok for trunk? > > Jiufu > > ChangeLog: > 2020-05-25 Jiufu Guo <guoji...@cn.ibm.com> > > * common.opt: Add -frtl-unroll-loops and -fcomplete-unroll-loops. > * opts.c (enable_fdo_optimizations): Replace flag_unroll_loops > with flag_complete_unroll_loops. > * toplev.c (process_options): set flag_rtl_unroll_loops and > flag_complete_unroll_loops if not explicitly set by user. > * tree-ssa-loop-ivcanon.c (pass_complete_unroll::execute): Replace > flag_unroll_loops with flag_complete_unroll_loops. > * loop-init.c (pass_loop2::gate): Replace flag_unroll_loops with > flag_rtl_unroll_loops. > (pass_rtl_unroll_loops::gate): Replace flag_unroll_loops with > flag_rtl_unroll_loops. > --- > gcc/common.opt | 8 ++++++++ > gcc/loop-init.c | 6 +++--- > gcc/opts.c | 2 +- > gcc/toplev.c | 6 ++++++ > gcc/tree-ssa-loop-ivcanon.c | 2 +- > 5 files changed, 19 insertions(+), 5 deletions(-) > > diff --git a/gcc/common.opt b/gcc/common.opt > index 4464049fc1f..3b5ab52bb9d 100644 > --- a/gcc/common.opt > +++ b/gcc/common.opt > @@ -2856,6 +2856,14 @@ funroll-all-loops > Common Report Var(flag_unroll_all_loops) Optimization > Perform loop unrolling for all loops. > > +frtl-unroll-loops > +Common Undocumented Var(flag_rtl_unroll_loops) Init(2) Optimization > +; Perform rtl loop unrolling when iteration count is known. > + > +fcomplete-unroll-loops > +Common Undocumented Var(flag_complete_unroll_loops) Init(2) Optimization > +; Perform GIMPLE loop complete unrolling. > + > ; Nonzero means that loop optimizer may assume that the induction variables > ; that control loops do not overflow and that the loops with nontrivial > ; exit condition are not infinite > diff --git a/gcc/loop-init.c b/gcc/loop-init.c > index 401e5282907..e955068f36c 100644 > --- a/gcc/loop-init.c > +++ b/gcc/loop-init.c > @@ -360,7 +360,7 @@ pass_loop2::gate (function *fun) > if (optimize > 0 > && (flag_move_loop_invariants > || flag_unswitch_loops > - || flag_unroll_loops > + || flag_rtl_unroll_loops > || (flag_branch_on_count_reg && targetm.have_doloop_end ()) > || cfun->has_unroll)) > return true; > @@ -560,7 +560,7 @@ public: > /* opt_pass methods: */ > virtual bool gate (function *) > { > - return (flag_unroll_loops || flag_unroll_all_loops || > cfun->has_unroll); > + return (flag_rtl_unroll_loops || flag_unroll_all_loops || > cfun->has_unroll); > } > > virtual unsigned int execute (function *); > @@ -576,7 +576,7 @@ pass_rtl_unroll_loops::execute (function *fun) > if (dump_file) > df_dump (dump_file); > > - if (flag_unroll_loops) > + if (flag_rtl_unroll_loops) > flags |= UAP_UNROLL; > if (flag_unroll_all_loops) > flags |= UAP_UNROLL_ALL; > diff --git a/gcc/opts.c b/gcc/opts.c > index ec3ca0720f9..64c35d8d7fc 100644 > --- a/gcc/opts.c > +++ b/gcc/opts.c > @@ -1702,7 +1702,7 @@ 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_complete_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, > diff --git a/gcc/toplev.c b/gcc/toplev.c > index 96316fbd23b..c2b94d33464 100644 > --- a/gcc/toplev.c > +++ b/gcc/toplev.c > @@ -1474,6 +1474,12 @@ process_options (void) > if (flag_unroll_all_loops) > flag_unroll_loops = 1; > > + if (flag_rtl_unroll_loops == AUTODETECT_VALUE) > + flag_rtl_unroll_loops = flag_unroll_loops; > + > + if (flag_complete_unroll_loops == AUTODETECT_VALUE) > + flag_complete_unroll_loops = flag_unroll_loops; > + > /* web and rename-registers help when run after loop unrolling. */ > if (flag_web == AUTODETECT_VALUE) > flag_web = flag_unroll_loops; > diff --git a/gcc/tree-ssa-loop-ivcanon.c b/gcc/tree-ssa-loop-ivcanon.c > index 8ab6ab3330c..cd5df353df5 100644 > --- a/gcc/tree-ssa-loop-ivcanon.c > +++ b/gcc/tree-ssa-loop-ivcanon.c > @@ -1603,7 +1603,7 @@ pass_complete_unroll::execute (function *fun) > re-peeling the same loop multiple times. */ > if (flag_peel_loops) > peeled_loops = BITMAP_ALLOC (NULL); > - unsigned int val = tree_unroll_loops_completely (flag_unroll_loops > + unsigned int val = tree_unroll_loops_completely (flag_complete_unroll_loops > || flag_peel_loops > || optimize >= 3, true); > if (peeled_loops) > -- > 2.17.1 >