Hi Jeff, on 2020/5/20 上午11:58, Jiufu Guo via Gcc-patches wrote: > Hi, > > This patch check the size of a loop to be unrolled/peeled completely, > and set the limits to a number (24). This prevents large loop from > being unrolled, then avoid binary size increasing, and this limit keeps > performance. > > Bootstrap®test pass on powerpc64le, ok for trunk? > > Jiufu > > --- > gcc/config/rs6000/rs6000.c | 19 ++++++++++++++++++- > 1 file changed, 18 insertions(+), 1 deletion(-) > > diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c > index a1a3f9cb583..f3abb92d046 100644 > --- a/gcc/config/rs6000/rs6000.c > +++ b/gcc/config/rs6000/rs6000.c > @@ -5142,6 +5142,22 @@ rs6000_loop_unroll_adjust (unsigned nunroll, struct > loop *loop) > return nunroll; > } > > +/* Count the number of statements in LOOP. */ > + > +static int > +num_stmt_in_loop (class loop *loop) > +{ > + int res = 0; > + basic_block *bbs = get_loop_body (loop); > + for (unsigned i = 0; i < loop->num_nodes; i++) > + for (gimple_stmt_iterator bsi = gsi_start_bb (bbs[i]); !gsi_end_p (bsi); > + gsi_next (&bsi)) > + if (!is_gimple_debug (gsi_stmt (bsi))) > + res++; > + > + return res; > +} > +
Would it be possible to use tree_num_loop_insns here? If no, this can be part of tree-ssa-loop.c, and we need to free(bbs). BR, Kewen > /* Implement targetm.loop_allow_unroll_completely_peel. */ > > static bool > @@ -5151,7 +5167,8 @@ rs6000_loop_allow_unroll_completely_peel (HOST_WIDE_INT > maxiter, tree niter, > if (unroll_only_small_loops && optimize == 2) > { > if (maxiter >= 4 > - && !(TREE_CODE (niter) == INTEGER_CST && single_exit (loop))) > + && !(TREE_CODE (niter) == INTEGER_CST && num_stmt_in_loop (loop) < 24 > + && single_exit (loop))) > return false; > } > >