[PATCH] Fix PR69823

Sebastian Pop sebpop@gmail.com
Wed Feb 8 17:31:00 GMT 2017


On Wed, Feb 8, 2017 at 8:34 AM, Richard Biener <rguenther@suse.de> wrote:
>
> The following fixes walking the SESE region when determining if it is
> valid.
>
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
>
> Will commit as obvious once that passed.

The change looks good.

Thanks,
Sebastian

>
> Thanks,
> Richard.
>
> 2017-02-08  Richard Biener  <rguenther@suse.de>
>
>         PR tree-optimization/69823
>         * graphite-scop-detection.c (scop_detection::harmful_loop_in_region):
>         Properly enumerate all BBs in the region.  Use auto_vec/auto_bitmap.
>
>         * gcc.dg/graphite/pr69823.c: New testcase.
>
> Index: gcc/graphite-scop-detection.c
> ===================================================================
> --- gcc/graphite-scop-detection.c       (revision 245276)
> +++ gcc/graphite-scop-detection.c       (working copy)
> @@ -1062,35 +1062,18 @@ scop_detection::harmful_loop_in_region (
>                print_sese (dump_file, scop));
>    gcc_assert (dominated_by_p (CDI_DOMINATORS, exit_bb, entry_bb));
>
> -  int depth = bb_dom_dfs_in (CDI_DOMINATORS, exit_bb)
> -    - bb_dom_dfs_in (CDI_DOMINATORS, entry_bb);
> +  auto_vec<basic_block> worklist;
> +  auto_bitmap loops;
>
> -  gcc_assert (depth > 0);
> -
> -  vec<basic_block> dom
> -      = get_dominated_to_depth (CDI_DOMINATORS, entry_bb, depth);
> -  int i;
> -  basic_block bb;
> -  bitmap loops = BITMAP_ALLOC (NULL);
> -  FOR_EACH_VEC_ELT (dom, i, bb)
> +  worklist.safe_push (entry_bb);
> +  while (! worklist.is_empty ())
>      {
> +      basic_block bb = worklist.pop ();
>        DEBUG_PRINT (dp << "Visiting bb_" << bb->index << "\n");
>
> -      /* We don't want to analyze any bb outside sese.  */
> -      if (!dominated_by_p (CDI_POST_DOMINATORS, bb, exit_bb))
> -       continue;
> -
> -      /* Basic blocks dominated by the scop->exit are not in the scop.  */
> -      if (bb != exit_bb && dominated_by_p (CDI_DOMINATORS, bb, exit_bb))
> -       continue;
> -
>        /* The basic block should not be part of an irreducible loop.  */
>        if (bb->flags & BB_IRREDUCIBLE_LOOP)
> -       {
> -         dom.release ();
> -         BITMAP_FREE (loops);
> -         return true;
> -       }
> +       return true;
>
>        /* Check for unstructured control flow: CFG not generated by structured
>          if-then-else.  */
> @@ -1114,13 +1097,14 @@ scop_detection::harmful_loop_in_region (
>              any loop fully contained in the scop: other bbs are checked below
>              in loop_is_valid_in_scop.  */
>           if (harmful_stmt_in_bb (scop, bb))
> -           {
> -             dom.release ();
> -             BITMAP_FREE (loops);
> -             return true;
> -           }
> +           return true;
>         }
>
> +      if (bb != exit_bb)
> +       for (basic_block dom = first_dom_son (CDI_DOMINATORS, bb);
> +            dom;
> +            dom = next_dom_son (CDI_DOMINATORS, dom))
> +         worklist.safe_push (dom);
>      }
>
>    /* Go through all loops and check that they are still valid in the combined
> @@ -1133,15 +1117,9 @@ scop_detection::harmful_loop_in_region (
>        gcc_assert (loop->num == (int) j);
>
>        if (!loop_is_valid_in_scop (loop, scop))
> -       {
> -         dom.release ();
> -         BITMAP_FREE (loops);
> -         return true;
> -       }
> +       return true;
>      }
>
> -  dom.release ();
> -  BITMAP_FREE (loops);
>    return false;
>  }
>
> Index: gcc/testsuite/gcc.dg/graphite/pr69823.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/graphite/pr69823.c     (nonexistent)
> +++ gcc/testsuite/gcc.dg/graphite/pr69823.c     (working copy)
> @@ -0,0 +1,20 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -floop-nest-optimize" } */
> +
> +void
> +foo (int c, int *p, int *a1, int *a2, int *a3)
> +{
> +  int i;
> +
> +  if (c)
> +    {
> +      for (i = 0; i < 8; i++)
> +       a1[i] = 1;
> +
> +      if (*p)
> +       *a2 = 0;
> +    }
> +
> +  for (i = 0; i < 8; i++)
> +    a3[i] = 0;
> +}



More information about the Gcc-patches mailing list