[PATCH] Fix PR37421, SCCVN not properly propagating constants in the lattice

Daniel Berlin dberlin@dberlin.org
Mon Sep 8 20:50:00 GMT 2008


This looks like the right fix to me.
Otherwise, things won't get folded and you will get the issue you hit ;(


On Mon, Sep 8, 2008 at 11:38 AM, Richard Guenther <rguenther@suse.de> wrote:
>
> SCCVN as visiting copies currently does not propagate constants.  Which
> causes interesting effects during expression lookup/insertion (see
> PR37421 audit).
>
> The following fixes that, bootstrap and regtest running on
> x86_64-unknown-linux-gnu.
>
> Richard.
>
> 2008-09-08  Richard Guenther  <rguenther@suse.de>
>
>        PR tree-optimization/37421
>        * tree-ssa-sccvn.c (visit_copy): Make sure to fully
>        valueize the RHS.
>
>        * g++.dg/torture/pr37421.C: New testcase.
>
> Index: gcc/tree-ssa-sccvn.c
> ===================================================================
> --- gcc/tree-ssa-sccvn.c        (revision 140104)
> +++ gcc/tree-ssa-sccvn.c        (working copy)
> @@ -1607,13 +1607,17 @@
>  visit_copy (tree lhs, tree rhs)
>  {
>   /* Follow chains of copies to their destination.  */
> -  while (SSA_VAL (rhs) != rhs && TREE_CODE (SSA_VAL (rhs)) == SSA_NAME)
> +  while (TREE_CODE (rhs) == SSA_NAME
> +        && SSA_VAL (rhs) != rhs)
>     rhs = SSA_VAL (rhs);
>
>   /* The copy may have a more interesting constant filled expression
>      (we don't, since we know our RHS is just an SSA name).  */
> -  VN_INFO (lhs)->has_constants = VN_INFO (rhs)->has_constants;
> -  VN_INFO (lhs)->expr = VN_INFO (rhs)->expr;
> +  if (TREE_CODE (rhs) == SSA_NAME)
> +    {
> +      VN_INFO (lhs)->has_constants = VN_INFO (rhs)->has_constants;
> +      VN_INFO (lhs)->expr = VN_INFO (rhs)->expr;
> +    }
>
>   return set_ssa_val_to (lhs, rhs);
>  }
> Index: gcc/testsuite/g++.dg/torture/pr37421.C
> ===================================================================
> --- gcc/testsuite/g++.dg/torture/pr37421.C      (revision 0)
> +++ gcc/testsuite/g++.dg/torture/pr37421.C      (revision 0)
> @@ -0,0 +1,39 @@
> +/* { dg-do compile } */
> +
> +#include <stdio.h>
> +#include <string.h>
> +
> +inline int
> +bci (const float &source)
> +{
> + int dest;
> + memcpy (&dest, &source, sizeof (dest));
> + return dest;
> +}
> +
> +inline float
> +bcf (const int &source)
> +{
> + float dest;
> + memcpy (&dest, &source, sizeof (dest));
> + return dest;
> +}
> +
> +float
> +Foo ()
> +{
> + const int foo = bci (0.0f);
> + int bar = foo;
> + const int baz = foo & 1;
> + if (!baz && (foo & 2))
> +   bar = 0;
> + return bcf (bar);
> +}
> +
> +int
> +main ()
> +{
> +  printf ("Foo() = %f\n", Foo());
> +  return 0;
> +}
> +
>



More information about the Gcc-patches mailing list