[patch] Fix -ftree-loop-distribution (PR tree-optimization/38997)

Sebastian Pop sebastian.pop@amd.com
Wed Jan 28 17:59:00 GMT 2009


On Wed, Jan 28, 2009 at 11:50 AM, Kazu Hirata <kazu@codesourcery.com> wrote:
> Hi,
>
> Attached is a patch to fix an ICE that's triggered by
> -ftree-loop-distribution.
>
> Consider the attached testcase.
>
> When the loop distributor tries to convert a[i][j] = 0 to a memset, it
> tries to come up with the base address for memset as:
>
>  &a[0][0] + (i * 64)
>
> with '+' being a PLUS_EXPR instead of POINTER_PLUS_EXPR.  Later,
> build2 becomes unhappy about a pointer addition with PLUS_EXPR and
> triggers an ICE.
>
> The patch fixes the problem by using POINTER_PLUS_EXPR instead.  Also,
> the second operand of POINTER_PLUS_EXPR must be of sizetype, so I've
> put fold_convert there.
>
> Tested on x86_64-pc-linux-gnu.  OK to apply?
>

The patch looks good, but I cannot approve it.

Thanks for fixing this,
Sebastian Pop
--
AMD - GNU Tools

> p.s.
> If I understand correctly, even in stage 3, non-regression bug fixes
> for a new pass and port are still accepted.  Is that correct?
>
> Kazu Hirata
>
> 2009-01-28  Kazu Hirata  <kazu@codesourcery.com>
>
>        PR tree-optimization/38997
>        * tree-loop-distribution.c (generate_memset_zero): Use
>        POINTER_PLUS_EXPR for a pointer addition.
>
> 2009-01-28  Kazu Hirata  <kazu@codesourcery.com>
>
>        PR tree-optimization/38997
>        * gcc.dg/tree-ssa/pr38997.c: New.
>
> Index: gcc/testsuite/gcc.dg/tree-ssa/pr38997.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/tree-ssa/pr38997.c     (revision 0)
> +++ gcc/testsuite/gcc.dg/tree-ssa/pr38997.c     (revision 0)
> @@ -0,0 +1,16 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -ftree-loop-distribution" } */
> +
> +int a[8][8];
> +int b[8];
> +
> +void
> +foo (int i)
> +{
> +  int j;
> +  for (j = 0; j < 8; j++)
> +    {
> +      a[i][j] = 0;
> +      b[j] = j;
> +    }
> +}
> Index: gcc/tree-loop-distribution.c
> ===================================================================
> --- gcc/tree-loop-distribution.c        (revision 143737)
> +++ gcc/tree-loop-distribution.c        (working copy)
> @@ -256,10 +256,15 @@ generate_memset_zero (gimple stmt, tree
>   /* Test for a positive stride, iterating over every element.  */
>   if (integer_zerop (fold_build2 (MINUS_EXPR, integer_type_node, DR_STEP (dr),
>                                  TYPE_SIZE_UNIT (TREE_TYPE (op0)))))
> -    addr_base = fold_build2 (PLUS_EXPR, TREE_TYPE (DR_BASE_ADDRESS (dr)),
> -                            DR_BASE_ADDRESS (dr),
> -                            size_binop (PLUS_EXPR,
> -                                        DR_OFFSET (dr), DR_INIT (dr)));
> +    {
> +      tree offset = fold_convert (sizetype,
> +                                 size_binop (PLUS_EXPR,
> +                                             DR_OFFSET (dr),
> +                                             DR_INIT (dr)));
> +      addr_base = fold_build2 (POINTER_PLUS_EXPR,
> +                              TREE_TYPE (DR_BASE_ADDRESS (dr)),
> +                              DR_BASE_ADDRESS (dr), offset);
> +    }
>
>   /* Test for a negative stride, iterating over every element.  */
>   else if (integer_zerop (fold_build2 (PLUS_EXPR, integer_type_node,
>



More information about the Gcc-patches mailing list