PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk

Andrew Pinski pinskia@gmail.com
Sat Mar 8 23:32:00 GMT 2008



Sent from my iPhone

On Mar 8, 2008, at 15:15, "H.J. Lu" <hjl.tools@gmail.com> wrote:

> On Sat, Mar 08, 2008 at 09:44:13PM +0100, Richard Guenther wrote:
>> On Fri, Mar 7, 2008 at 11:07 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Fri, Mar 7, 2008 at 11:11 AM, H.J. Lu <hjl.tools@gmail.com>  
>>> wrote:
>>>> Compiler will allocate space for
>>>>
>>>> const int conststaticvariable;
>>>>
>>>> You just may not know what value will be in all cases. Here is the
>>>> updated with additional testcases. OK to install if tests on  
>>>> Linux/x86
>>>> and Linux/Intel64 as well as 483.xalancbmk passes?
>>>>
>>>
>>> All tests are passed. OK to install on trunk?
>>
>> Yes.
>>
>
> It turns out to be a tricky issue. We need to check if a read-only
> symbol may be overridden at both run time and link time. I can't
> use targetm.binds_local_p since it only tells me if a symbol may be
> overridden at run time by another module. It returns fals positive
> for
>
> class Foo {
> public:
>  static const int erf = 0;
> };
>
> since C++ sets DECL_EXTERNAL to 1. Also it doesn't tell me if a
> symbol may be overridden by another definition at link time. I
>
> I opened PR 35501 for run time issue. I am testing this patch for
> both PR 35494 and 35501 on Linux/ia32 and Linux/Intel as well as
> 483.xalancbmk. OK to install if all tests pass?
>
>
> H.J.
> ---
> gcc/
>
> 2008-03-08  H.J. Lu  <hongjiu.lu@intel.com>
>
>    PR tree-optimization/35501
>    * c-typeck.c (decl_constant_value): Check if value may be
>    overriden at run time.
>    * tree-ssa-sccvn.c (try_to_simplify): Likewise.
>
>    PR tree-optimization/35494
>    PR tree-optimization/35501
>    * tree-ssa-ccp.c (get_symbol_constant_value): Check if value
>    may be overriden at link and run time.
>
> gcc/testsuite/
>
> 2008-03-07  H.J. Lu  <hongjiu.lu@intel.com>
>
>    PR tree-optimization/35494
>    * g++.dg/tree-ssa/ssa-store-ccp-1.C: New.
>    * gcc.dg/tree-ssa/ssa-store-ccp-2.c: Likewise.
>    * gcc.dg/tree-ssa/ssa-store-ccp-3.c: Likewise.
>    * gcc.dg/tree-ssa/ssa-store-ccp-4.c: Likewise.
>
>    PR tree-optimization/35501
>    * gcc.dg/pr35501-1.c: New.
>    * gcc.dg/pr35501-2.c: Likewise.
>    * gcc.dg/pr35501-3.c: Likewise.
>    * gcc.dg/pr35501-4.c: Likewise.
>
> --- gcc/c-typeck.c.local    2008-02-26 09:27:22.000000000 -0800
> +++ gcc/c-typeck.c    2008-03-08 14:44:29.000000000 -0800
> @@ -1551,7 +1551,10 @@ decl_constant_value (tree decl)
>     or a variable, then re-evaluating it could give different  
> results.  */
>       && TREE_CONSTANT (DECL_INITIAL (decl))
>       /* Check for cases where this is sub-optimal, even though  
> valid.  */
> -      && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR)
> +      && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
> +      /* Check if it may be overriden at run time.  */
> +      && (!flag_shlib
> +      || DECL_VISIBILITY (decl) != VISIBILITY_DEFAULT))
>     return DECL_INITIAL (decl);

This is only true with elf semantics;  mach-o semantics say that a  
variable in a shared library is not overwritable.



>
>   return decl;
> }
> --- gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C.local     
> 2008-03-08 14:44:29.000000000 -0800
> +++ gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C    2008-03-08  
> 14:48:55.000000000 -0800
> @@ -0,0 +1,19 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +
> +class bar
> +{
> +public:
> +  static const int conststaticvariable;
> +};
> +
> +
> +int f(void)
> +{
> +  return bar::conststaticvariable;
> +}
> +
> +/* There should be a reference to conststaticvariable since it may
> +   be overriden at link time.  */
> +/* { dg-final { scan-tree-dump-times "conststaticvariable" 1  
> "optimized"} } */
> +/* { dg-final { cleanup-tree-dump "optimized" } } */
> --- gcc/testsuite/gcc.dg/pr35501-1.c.local    2008-03-08 14:44:29.000000000 -0800
> +++ gcc/testsuite/gcc.dg/pr35501-1.c    2008-03-08 14:44:29.000000000 -0800
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O -fdump-tree-optimized" } */
> +
> +const int conststaticvariable = 1;
> +
> +int f(void)
> +{
> +  return conststaticvariable;
> +}
> +
> +/* There should be no reference to conststaticvariable as we should  
> have
> +   inlined the 0. */
> +/* { dg-final { scan-tree-dump-times "conststaticvariable" 0  
> "optimized"} } */
> +/* { dg-final { cleanup-tree-dump "optimized" } } */
> --- gcc/testsuite/gcc.dg/pr35501-2.c.local    2008-03-08 14:44:29.000000000 -0800
> +++ gcc/testsuite/gcc.dg/pr35501-2.c    2008-03-08 14:44:29.000000000 -0800
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +
> +const int conststaticvariable = 1;
> +
> +int f(void)
> +{
> +  return conststaticvariable;
> +}
> +
> +/* There should be no reference to conststaticvariable as we should  
> have
> +   inlined the 0. */
> +/* { dg-final { scan-tree-dump-times "conststaticvariable" 0  
> "optimized"} } */
> +/* { dg-final { cleanup-tree-dump "optimized" } } */
> --- gcc/testsuite/gcc.dg/pr35501-3.c.local    2008-03-08 14:44:29.000000000 -0800
> +++ gcc/testsuite/gcc.dg/pr35501-3.c    2008-03-08 14:50:02.000000000 -0800
> @@ -0,0 +1,15 @@
> +/* { dg-do compile } */
> +/* { dg-require-effective-target fpic } */
> +/* { dg-options "-O -fpic -fdump-tree-optimized" } */
> +
> +const int conststaticvariable = 1;
> +
> +int f(void)
> +{
> +  return conststaticvariable;
> +}
> +
> +/* There should be a reference to conststaticvariable since it may
> +   may be overriden at run time.  */
> +/* { dg-final { scan-tree-dump-times "conststaticvariable" 1  
> "optimized"} } */
> +/* { dg-final { cleanup-tree-dump "optimized" } } */
> --- gcc/testsuite/gcc.dg/pr35501-4.c.local    2008-03-08 14:44:29.000000000 -0800
> +++ gcc/testsuite/gcc.dg/pr35501-4.c    2008-03-08 14:50:10.000000000 -0800
> @@ -0,0 +1,15 @@
> +/* { dg-do compile } */
> +/* { dg-require-effective-target fpic } */
> +/* { dg-options "-O2 -fpic -fdump-tree-optimized" } */
> +
> +const int conststaticvariable = 1;
> +
> +int f(void)
> +{
> +  return conststaticvariable;
> +}
> +
> +/* There should be a reference to conststaticvariable since it may
> +   may be overriden at run time.  */
> +/* { dg-final { scan-tree-dump-times "conststaticvariable" 1  
> "optimized"} } */
> +/* { dg-final { cleanup-tree-dump "optimized" } } */
> --- gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-2.c.local     
> 2008-03-08 14:44:29.000000000 -0800
> +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-2.c    2008-03-08  
> 14:48:43.000000000 -0800
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +
> +const int conststaticvariable;
> +
> +int f(void)
> +{
> +  return conststaticvariable;
> +}
> +
> +/* There should be a reference to conststaticvariable since it may
> +   may be overriden at link time.  */
> +/* { dg-final { scan-tree-dump-times "conststaticvariable" 1  
> "optimized"} } */
> +/* { dg-final { cleanup-tree-dump "optimized" } } */
> --- gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-3.c.local     
> 2008-03-08 14:44:29.000000000 -0800
> +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-3.c    2008-03-08  
> 14:44:29.000000000 -0800
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fno-common -fdump-tree-optimized" } */
> +
> +const int conststaticvariable;
> +
> +int f(void)
> +{
> +  return conststaticvariable;
> +}
> +
> +/* There should be no reference to conststaticvariable as we should  
> have
> +   inlined the 0. */
> +/* { dg-final { scan-tree-dump-times "conststaticvariable" 0  
> "optimized"} } */
> +/* { dg-final { cleanup-tree-dump "optimized" } } */
> --- gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-4.c.local     
> 2008-03-08 14:44:29.000000000 -0800
> +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-4.c    2008-03-08  
> 14:49:35.000000000 -0800
> @@ -0,0 +1,15 @@
> +/* { dg-do compile } */
> +/* { dg-require-effective-target fpic } */
> +/* { dg-options "-O2 -fno-common -fpic -fdump-tree-optimized" } */
> +
> +const int conststaticvariable;
> +
> +int f(void)
> +{
> +  return conststaticvariable;
> +}
> +
> +/* There should be a reference to conststaticvariable since it may
> +   may be overriden at run time.  */
> +/* { dg-final { scan-tree-dump-times "conststaticvariable" 1  
> "optimized"} } */
> +/* { dg-final { cleanup-tree-dump "optimized" } } */
> --- gcc/tree-ssa-ccp.c.local    2008-03-07 09:02:37.000000000 -0800
> +++ gcc/tree-ssa-ccp.c    2008-03-08 14:52:43.000000000 -0800
> @@ -300,15 +300,21 @@ get_symbol_constant_value (tree sym)
> {
>   if (TREE_STATIC (sym)
>       && TREE_READONLY (sym)
> -      && !MTAG_P (sym))
> +      && !MTAG_P (sym)
> +      /* Check if a read-only definition may be overridden at
> +     run time.  */
> +      && (!flag_shlib
> +      || DECL_VISIBILITY (sym) != VISIBILITY_DEFAULT))
>     {
>       tree val = DECL_INITIAL (sym);
>       if (val
>      && ccp_decl_initial_min_invariant (val))
>    return val;
> -      /* Variables declared 'const' without an initializer
> -     have zero as the intializer.  */
> +      /* Variables declared 'const' without an initializer have
> +     zero as the intializer if it won't be overridden at
> +     link time.  */
>       if (!val
> +      && (!TREE_PUBLIC (sym) || !DECL_EXTERNAL (sym))
>           && (INTEGRAL_TYPE_P (TREE_TYPE (sym))
>           || SCALAR_FLOAT_TYPE_P (TREE_TYPE (sym))))
>         return fold_convert (TREE_TYPE (sym), integer_zero_node);
> --- gcc/tree-ssa-sccvn.c.local    2008-03-08 14:41:18.000000000 -0800
> +++ gcc/tree-ssa-sccvn.c    2008-03-08 14:44:29.000000000 -0800
> @@ -1453,6 +1453,9 @@ try_to_simplify (tree stmt, tree rhs)
>      if (TREE_READONLY (rhs)
>          && TREE_STATIC (rhs)
>          && DECL_INITIAL (rhs)
> +          /* Check if it may be overriden at run time.  */
> +          && (!flag_shlib
> +          || DECL_VISIBILITY (rhs) != VISIBILITY_DEFAULT)
>          && valid_gimple_expression_p (DECL_INITIAL (rhs)))
>        return DECL_INITIAL (rhs);
>



More information about the Gcc-patches mailing list