[PATCH] Fix number_of_iterations_cond (PR tree-optimization/53550)

Richard Guenther richard.guenther@gmail.com
Mon Jun 4 09:14:00 GMT 2012


On Sat, Jun 2, 2012 at 9:48 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> tree-chrec.c and tree-scalar-evolutions.c uses sizetype as type of
> iv->step, but the following spot would use POINTER_TYPE, which leads
> to ICEs.  Fixed thusly, bootstrapped/regtested onx 86_64-linux and
> i686-linux, ok for trunk/4.7?

Ok.

Thanks,
Richard.

> 2012-06-02  Jakub Jelinek  <jakub@redhat.com>
>
>        PR tree-optimization/53550
>        * tree-ssa-loop-niter.c (number_of_iterations_cond): If type
>        is POINTER_TYPE_P, use sizetype as step type instead of type.
>
>        * gcc.dg/pr53550.c: New test.
>
> --- gcc/tree-ssa-loop-niter.c.jj        2012-06-01 14:40:59.336398386 +0200
> +++ gcc/tree-ssa-loop-niter.c   2012-06-01 17:52:09.128317401 +0200
> @@ -1275,13 +1275,14 @@ number_of_iterations_cond (struct loop *
>      practice, but it is simple enough to manage.  */
>   if (!integer_zerop (iv0->step) && !integer_zerop (iv1->step))
>     {
> +      tree step_type = POINTER_TYPE_P (type) ? sizetype : type;
>       if (code != NE_EXPR)
>        return false;
>
> -      iv0->step = fold_binary_to_constant (MINUS_EXPR, type,
> +      iv0->step = fold_binary_to_constant (MINUS_EXPR, step_type,
>                                           iv0->step, iv1->step);
>       iv0->no_overflow = false;
> -      iv1->step = build_int_cst (type, 0);
> +      iv1->step = build_int_cst (step_type, 0);
>       iv1->no_overflow = true;
>     }
>
> --- gcc/testsuite/gcc.dg/pr53550.c.jj   2012-06-01 17:52:09.128317401 +0200
> +++ gcc/testsuite/gcc.dg/pr53550.c      2012-06-02 08:53:53.345935193 +0200
> @@ -0,0 +1,12 @@
> +/* PR tree-optimization/53550 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fprefetch-loop-arrays -w" } */
> +
> +int *
> +foo (int *x)
> +{
> +  int *a = x + 10, *b = x, *c = a;
> +  while (b != c)
> +    *--c = *b++;
> +  return x;
> +}
>
>        Jakub



More information about the Gcc-patches mailing list