On 4/29/2021 3:50 AM, Jiufu Guo via Gcc-patches wrote:
When there is the possibility that overflow may happen on the loop index,
a few optimizations would not happen. For example code:

foo (int *a, int *b, unsigned k, unsigned n)
{
   while (++k != n)
     a[k] = b[k]  + 1;
}

For this code, if "l > n", overflow may happen.  if "l < n" at begining,
it could be optimized (e.g. vectorization).

We can split the loop into two loops:

   while (++k > n)
     a[k] = b[k]  + 1;
   while (l++ < n)
     a[k] = b[k]  + 1;

then for the second loop, it could be optimized.

This patch is spltting this kind of small loop to achieve better performance.

Bootstrap and regtest pass on ppc64le.  Is this ok for trunk?

Thanks!

Jiufu Guo.

gcc/ChangeLog:

2021-04-29  Jiufu Guo  <guoji...@linux.ibm.com>

        * params.opt (max-insns-ne-cond-split): New.
        * tree-ssa-loop-split.c (connect_loop_phis): Add new param.
        (get_ne_cond_branch): New function.
        (split_ne_loop): New function.
        (split_loop_on_ne_cond): New function.
        (tree_ssa_split_loops): Use split_loop_on_ne_cond.

I haven't looked at the patch in any detail, but I wonder if the same concept could be used to fix pr59371, which is a long standing regression.  Yea, it's reported against MIPS, but the concepts are fairly generic.

Jeff

Reply via email to