[PATCH] Fix remove_visited_stmt_chain (PR tree-optimization/38807)

Richard Guenther richard.guenther@gmail.com
Mon Jan 12 11:04:00 GMT 2009


On Mon, Jan 12, 2009 at 11:46 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> When adding this function, I assumed that all visited flags
> are cleared during break_up_subtract_bb and then afterwards only set
> on GIMPLE_STMTS.  But that's not true, break_up_subtract_bb
> clears it only for bb stmts, but doesn't walk through bb phis to clear
> their visited bits.  While we could do that, it seems like a waste,
> it doesn't hurt to verify that stmt is GIMPLE_ASSIGN before
> using gimple_assign_rhs1 on it anyway and that rules out GIMPLE_PHIs.
>
> Bootstrapped/regtested on {x86_64,i686}-linux, ok for trunk?

Ok.

Thanks,
Richard.

> 2009-01-12  Jakub Jelinek  <jakub@redhat.com>
>
>        PR tree-optimization/38807
>        * tree-ssa-reassoc.c (remove_visited_stmt_chain): Don't look at
>        gimple_visited_p unless stmt is GIMPLE_ASSIGN.
>
>        * gcc.c-torture/compile/pr38807.c: New test.
>
> --- gcc/tree-ssa-reassoc.c.jj   2008-12-18 08:53:30.000000000 +0100
> +++ gcc/tree-ssa-reassoc.c      2009-01-12 09:50:24.000000000 +0100
> @@ -1,5 +1,5 @@
>  /* Reassociation for trees.
> -   Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
> +   Copyright (C) 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
>    Contributed by Daniel Berlin <dan@dberlin.org>
>
>  This file is part of GCC.
> @@ -1279,7 +1279,8 @@ remove_visited_stmt_chain (tree var)
>       if (TREE_CODE (var) != SSA_NAME || !has_zero_uses (var))
>        return;
>       stmt = SSA_NAME_DEF_STMT (var);
> -      if (!gimple_visited_p (stmt))
> +      if (!is_gimple_assign (stmt)
> +         || !gimple_visited_p (stmt))
>        return;
>       var = gimple_assign_rhs1 (stmt);
>       gsi = gsi_for_stmt (stmt);
> --- gcc/testsuite/gcc.c-torture/compile/pr38807.c.jj    2009-01-12 09:52:17.000000000 +0100
> +++ gcc/testsuite/gcc.c-torture/compile/pr38807.c       2009-01-12 09:51:58.000000000 +0100
> @@ -0,0 +1,23 @@
> +/* PR tree-optimization/38807 */
> +
> +int
> +baz (short x)
> +{
> +  return x;
> +}
> +
> +int a, b;
> +
> +int
> +bar (int x)
> +{
> +  if (baz (a ^ x ^ a))
> +    return b;
> +  return 0;
> +}
> +
> +int
> +foo (void)
> +{
> +  return bar (a == 0 || 1 == 1 - a) ? 1 : bar (1 && a);
> +}
>
>        Jakub
>



More information about the Gcc-patches mailing list