This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR61385: phiopt drops some PHIs
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Marc Glisse <marc dot glisse at inria dot fr>
- Cc: Jeff Law <law at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 4 Jun 2014 13:41:07 +0200
- Subject: Re: PR61385: phiopt drops some PHIs
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot DEB dot 2 dot 02 dot 1406031538380 dot 730 at stedding dot saclay dot inria dot fr> <CAFiYyc3Rm+KGkG2LTGAArpene-C6jmh0A9aJWSq7nR2HmTDC3Q at mail dot gmail dot com> <538E0915 dot 3090606 at redhat dot com> <alpine dot DEB dot 2 dot 10 dot 1406032016520 dot 2149 at laptop-mg dot saclay dot inria dot fr> <538ED1F5 dot 9070707 at redhat dot com> <CAFiYyc0BD1RsKg7=KvnXBx8-0WqKJvQLSFikdXgFYtvnvQcsmA at mail dot gmail dot com> <alpine dot DEB dot 2 dot 02 dot 1406041254330 dot 7525 at stedding dot saclay dot inria dot fr>
On Wed, Jun 4, 2014 at 1:20 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Wed, 4 Jun 2014, Richard Biener wrote:
>
>> So I'd say we should instead simply bail out if the middle-bb has a PHI
>> node.
>
>
> Sounds good to me, so I am testing the mini-patch I had originally posted to
> bugzilla:
Ok.
Thanks,
Richard.
>
> 2014-06-04 Marc Glisse <marc.glisse@inria.fr>
>
> PR tree-optimization/61385
> gcc/
> * tree-ssa-phiopt.c (value_replacement): Punt if there are PHI
> nodes.
>
> gcc/testsuite/
> * gcc.dg/tree-ssa/pr61385.c: New file.
>
> --
> Marc Glisse
> Index: gcc/testsuite/gcc.dg/tree-ssa/pr61385.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/tree-ssa/pr61385.c (revision 0)
> +++ gcc/testsuite/gcc.dg/tree-ssa/pr61385.c (working copy)
> @@ -0,0 +1,43 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2" } */
> +
> +#define assert(x) if (!(x)) __builtin_abort ()
> +
> +int a, b, c, d, e, f, g;
> +
> +int
> +fn1 ()
> +{
> + int *h = &c;
> + for (; c < 1; c++)
> + {
> + int *i = &a, *k = &a;
> + f = 0;
> + if (b)
> + return 0;
> + if (*h)
> + {
> + int **j = &i;
> + *j = 0;
> + d = 0;
> + }
> + else
> + g = e = 0;
> + if (*h)
> + {
> + int **l = &k;
> + *l = &g;
> + }
> + d &= *h;
> + assert (k == &a || k);
> + assert (i);
> + }
> + return 0;
> +}
> +
> +int
> +main ()
> +{
> + fn1 ();
> + return 0;
> +}
> Index: gcc/tree-ssa-phiopt.c
> ===================================================================
> --- gcc/tree-ssa-phiopt.c (revision 211221)
> +++ gcc/tree-ssa-phiopt.c (working copy)
> @@ -842,20 +842,24 @@ value_replacement (basic_block cond_bb,
> /* Now optimize (x != 0) ? x + y : y to just y.
> The following condition is too restrictive, there can easily be
> another
> stmt in middle_bb, for instance a CONVERT_EXPR for the second
> argument. */
> gimple assign = last_and_only_stmt (middle_bb);
> if (!assign || gimple_code (assign) != GIMPLE_ASSIGN
> || gimple_assign_rhs_class (assign) != GIMPLE_BINARY_RHS
> || (!INTEGRAL_TYPE_P (TREE_TYPE (arg0))
> && !POINTER_TYPE_P (TREE_TYPE (arg0))))
> return 0;
>
> + /* Punt if there are (degenerate) PHIs in middle_bb, there should not be.
> */
> + if (!gimple_seq_empty_p (phi_nodes (middle_bb)))
> + return 0;
> +
> /* Only transform if it removes the condition. */
> if (!single_non_singleton_phi_for_edges (phi_nodes (gimple_bb (phi)), e0,
> e1))
> return 0;
>
> /* Size-wise, this is always profitable. */
> if (optimize_bb_for_speed_p (cond_bb)
> /* The special case is useless if it has a low probability. */
> && profile_status_for_fn (cfun) != PROFILE_ABSENT
> && EDGE_PRED (middle_bb, 0)->probability < PROB_EVEN
> /* If assign is cheap, there is no point avoiding it. */
>