public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision  132991 breaks 483.xalancbmk
@ 2008-03-07 15:00 H.J. Lu
  2008-03-07 15:19 ` Richard Guenther
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: H.J. Lu @ 2008-03-07 15:00 UTC (permalink / raw)
  To: gcc-patches

We can't fold glocal variables with NULL DECL_INITIAL. I am testing it
on Linux/x86 and Linux/Intel64 as well as 483.xalancbmk. OK to install
if all pass?


H.J.
----
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/

2008-03-07  H.J. Lu  <hongjiu.lu@intel.com>

	PR tree-optimization/35494
	* tree-ssa-ccp.c (get_symbol_constant_value): Only fold local
	variables with NULL DECL_INITIAL.

--- gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C.local	2008-03-07 06:45:42.000000000 -0800
+++ gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C	2008-03-07 06:44:53.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 is
+   global.  */
+/* { 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-07 06:58:07.000000000 -0800
+++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-2.c	2008-03-07 06:58:38.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 1 reference to conststaticvariable since it is
+   global.  */
+/* { dg-final { scan-tree-dump-times "conststaticvariable" 1 "optimized"} } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
--- gcc/tree-ssa-ccp.c.local	2008-03-06 14:18:27.000000000 -0800
+++ gcc/tree-ssa-ccp.c	2008-03-07 06:21:57.000000000 -0800
@@ -306,9 +306,10 @@ get_symbol_constant_value (tree sym)
       if (val
 	  && ccp_decl_initial_min_invariant (val))
 	return val;
-      /* Variables declared 'const' without an initializer
+      /* Local variables declared 'const' without an initializer
 	 have zero as the intializer.  */
       if (!val
+	  && !TREE_PUBLIC (sym)
           && (INTEGRAL_TYPE_P (TREE_TYPE (sym))
 	       || SCALAR_FLOAT_TYPE_P (TREE_TYPE (sym))))
         return fold_convert (TREE_TYPE (sym), integer_zero_node);

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk
  2008-03-07 15:00 PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk H.J. Lu
@ 2008-03-07 15:19 ` Richard Guenther
  2008-03-07 15:30   ` H.J. Lu
  2008-03-09 14:43   ` H.J. Lu
  2008-03-07 16:39 ` Andrew Pinski
  2008-03-07 17:00 ` Andrew Pinski
  2 siblings, 2 replies; 16+ messages in thread
From: Richard Guenther @ 2008-03-07 15:19 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches

On Fri, Mar 7, 2008 at 4:00 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> We can't fold glocal variables with NULL DECL_INITIAL. I am testing it
>  on Linux/x86 and Linux/Intel64 as well as 483.xalancbmk. OK to install
>  if all pass?

Hm, use targetm.binds_local_p instead?

Thanks,
Richard.

>  H.J.
>  ----
>  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/
>
>  2008-03-07  H.J. Lu  <hongjiu.lu@intel.com>
>
>         PR tree-optimization/35494
>         * tree-ssa-ccp.c (get_symbol_constant_value): Only fold local
>         variables with NULL DECL_INITIAL.
>
>  --- gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C.local       2008-03-07 06:45:42.000000000 -0800
>  +++ gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C     2008-03-07 06:44:53.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 is
>  +   global.  */
>  +/* { 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-07 06:58:07.000000000 -0800
>  +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-2.c     2008-03-07 06:58:38.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 1 reference to conststaticvariable since it is
>  +   global.  */
>  +/* { dg-final { scan-tree-dump-times "conststaticvariable" 1 "optimized"} } */
>  +/* { dg-final { cleanup-tree-dump "optimized" } } */
>  --- gcc/tree-ssa-ccp.c.local    2008-03-06 14:18:27.000000000 -0800
>  +++ gcc/tree-ssa-ccp.c  2008-03-07 06:21:57.000000000 -0800
>  @@ -306,9 +306,10 @@ get_symbol_constant_value (tree sym)
>        if (val
>           && ccp_decl_initial_min_invariant (val))
>         return val;
>  -      /* Variables declared 'const' without an initializer
>  +      /* Local variables declared 'const' without an initializer
>          have zero as the intializer.  */
>        if (!val
>  +         && !TREE_PUBLIC (sym)
>            && (INTEGRAL_TYPE_P (TREE_TYPE (sym))
>                || SCALAR_FLOAT_TYPE_P (TREE_TYPE (sym))))
>          return fold_convert (TREE_TYPE (sym), integer_zero_node);
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision  132991 breaks 483.xalancbmk
  2008-03-07 15:19 ` Richard Guenther
@ 2008-03-07 15:30   ` H.J. Lu
  2008-03-07 15:40     ` Richard Guenther
  2008-03-09 14:43   ` H.J. Lu
  1 sibling, 1 reply; 16+ messages in thread
From: H.J. Lu @ 2008-03-07 15:30 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches

On Fri, Mar 07, 2008 at 04:19:01PM +0100, Richard Guenther wrote:
> On Fri, Mar 7, 2008 at 4:00 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> > We can't fold glocal variables with NULL DECL_INITIAL. I am testing it
> >  on Linux/x86 and Linux/Intel64 as well as 483.xalancbmk. OK to install
> >  if all pass?
> 
> Hm, use targetm.binds_local_p instead?
> 

I don't think targetm.binds_local_p is appropriate here.
targetm.binds_local_p tells me if a symbol is local to
the module, which may consist of many files, and a symbol
local to the module may be initialized to a different value
in another file.  But here we want to check if a symbol local
to the file.


H.J.
----
> Thanks,
> Richard.
> 
> >  H.J.
> >  ----
> >  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/
> >
> >  2008-03-07  H.J. Lu  <hongjiu.lu@intel.com>
> >
> >         PR tree-optimization/35494
> >         * tree-ssa-ccp.c (get_symbol_constant_value): Only fold local
> >         variables with NULL DECL_INITIAL.
> >
> >  --- gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C.local       2008-03-07 06:45:42.000000000 -0800
> >  +++ gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C     2008-03-07 06:44:53.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 is
> >  +   global.  */
> >  +/* { 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-07 06:58:07.000000000 -0800
> >  +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-2.c     2008-03-07 06:58:38.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 1 reference to conststaticvariable since it is
> >  +   global.  */
> >  +/* { dg-final { scan-tree-dump-times "conststaticvariable" 1 "optimized"} } */
> >  +/* { dg-final { cleanup-tree-dump "optimized" } } */
> >  --- gcc/tree-ssa-ccp.c.local    2008-03-06 14:18:27.000000000 -0800
> >  +++ gcc/tree-ssa-ccp.c  2008-03-07 06:21:57.000000000 -0800
> >  @@ -306,9 +306,10 @@ get_symbol_constant_value (tree sym)
> >        if (val
> >           && ccp_decl_initial_min_invariant (val))
> >         return val;
> >  -      /* Variables declared 'const' without an initializer
> >  +      /* Local variables declared 'const' without an initializer
> >          have zero as the intializer.  */
> >        if (!val
> >  +         && !TREE_PUBLIC (sym)
> >            && (INTEGRAL_TYPE_P (TREE_TYPE (sym))
> >                || SCALAR_FLOAT_TYPE_P (TREE_TYPE (sym))))
> >          return fold_convert (TREE_TYPE (sym), integer_zero_node);
> >

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk
  2008-03-07 15:30   ` H.J. Lu
@ 2008-03-07 15:40     ` Richard Guenther
  0 siblings, 0 replies; 16+ messages in thread
From: Richard Guenther @ 2008-03-07 15:40 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches

On Fri, Mar 7, 2008 at 4:30 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Mar 07, 2008 at 04:19:01PM +0100, Richard Guenther wrote:
>  > On Fri, Mar 7, 2008 at 4:00 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>  > > We can't fold glocal variables with NULL DECL_INITIAL. I am testing it
>  > >  on Linux/x86 and Linux/Intel64 as well as 483.xalancbmk. OK to install
>  > >  if all pass?
>  >
>  > Hm, use targetm.binds_local_p instead?
>  >
>
>  I don't think targetm.binds_local_p is appropriate here.
>  targetm.binds_local_p tells me if a symbol is local to
>  the module, which may consist of many files, and a symbol
>  local to the module may be initialized to a different value
>  in another file.  But here we want to check if a symbol local
>  to the file.

The patch is ok then if testing passes.

Richard.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision  132991 breaks 483.xalancbmk
  2008-03-07 15:00 PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk H.J. Lu
  2008-03-07 15:19 ` Richard Guenther
@ 2008-03-07 16:39 ` Andrew Pinski
  2008-03-07 17:00 ` Andrew Pinski
  2 siblings, 0 replies; 16+ messages in thread
From: Andrew Pinski @ 2008-03-07 16:39 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches



Sent from my iPhone

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

> We can't fold glocal variables with NULL DECL_INITIAL. I am testing it
> on Linux/x86 and Linux/Intel64 as well as 483.xalancbmk. OK to install
> if all pass?
>
>
> H.J.
> ----
> 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/
>
> 2008-03-07  H.J. Lu  <hongjiu.lu@intel.com>
>
>    PR tree-optimization/35494
>    * tree-ssa-ccp.c (get_symbol_constant_value): Only fold local
>    variables with NULL DECL_INITIAL.
>
> --- gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C.local     
> 2008-03-07 06:45:42.000000000 -0800
> +++ gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C    2008-03-07  
> 06:44:53.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 is
> +   global.  */
> +/* { 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-07 06:58:07.000000000 -0800
> +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-2.c    2008-03-07  
> 06:58:38.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 1 reference to conststaticvariable since it is
> +   global.  */
> +/* { dg-final { scan-tree-dump-times "conststaticvariable" 1  
> "optimized"} } */
> +/* { dg-final { cleanup-tree-dump "optimized" } } */
> --- gcc/tree-ssa-ccp.c.local    2008-03-06 14:18:27.000000000 -0800
> +++ gcc/tree-ssa-ccp.c    2008-03-07 06:21:57.000000000 -0800
> @@ -306,9 +306,10 @@ get_symbol_constant_value (tree sym)
>       if (val
>      && ccp_decl_initial_min_invariant (val))
>    return val;
> -      /* Variables declared 'const' without an initializer
> +      /* Local variables declared 'const' without an initializer
>     have zero as the intializer.  */
>       if (!val
> +      && !TREE_PUBLIC (sym)


This check should be early; for the case where it is initialized also.



>
>           && (INTEGRAL_TYPE_P (TREE_TYPE (sym))
>           || SCALAR_FLOAT_TYPE_P (TREE_TYPE (sym))))
>         return fold_convert (TREE_TYPE (sym), integer_zero_node);

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk
  2008-03-07 15:00 PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk H.J. Lu
  2008-03-07 15:19 ` Richard Guenther
  2008-03-07 16:39 ` Andrew Pinski
@ 2008-03-07 17:00 ` Andrew Pinski
  2008-03-07 19:11   ` H.J. Lu
  2 siblings, 1 reply; 16+ messages in thread
From: Andrew Pinski @ 2008-03-07 17:00 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches

On 3/7/08, H.J. Lu <hjl.tools@gmail.com> wrote:
> We can't fold glocal variables with NULL DECL_INITIAL. I am testing it
>  on Linux/x86 and Linux/Intel64 as well as 483.xalancbmk. OK to install
>  if all pass?

This patch is wrong because currently we check TREE_STATIC which says
we allocate space for the variable:
/* In a VAR_DECL, nonzero means allocate static storage.
   In a FUNCTION_DECL, nonzero if function has been defined.
   In a CONSTRUCTOR, nonzero means allocate static storage.

   ??? This is also used in lots of other nodes in unclear ways which
   should be cleaned up some day.  */

TREE_STATIC should not be set on those variables as there is no space
allocated in the case of the C++ case (I think Ada case also).

Also "const int conststaticvariable;" in C is global but it will be
put in the common section and is called a tentative definition.  So
there needs to be another check for that instead of just TREE_PUBLIC.
That is if you compile:
const int conststaticvariable;

int f(void)
{
  return conststaticvariable;
}
With -fno-common, the tentative definition is no longer one and we
should be able to optimize it.

Thanks,
Andrew Pinski

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk
  2008-03-07 17:00 ` Andrew Pinski
@ 2008-03-07 19:11   ` H.J. Lu
  2008-03-07 22:07     ` H.J. Lu
  0 siblings, 1 reply; 16+ messages in thread
From: H.J. Lu @ 2008-03-07 19:11 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1584 bytes --]

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?

H.J.
On Fri, Mar 7, 2008 at 9:00 AM, Andrew Pinski <pinskia@gmail.com> wrote:
> On 3/7/08, H.J. Lu <hjl.tools@gmail.com> wrote:
>  > We can't fold glocal variables with NULL DECL_INITIAL. I am testing it
>  >  on Linux/x86 and Linux/Intel64 as well as 483.xalancbmk. OK to install
>  >  if all pass?
>
>  This patch is wrong because currently we check TREE_STATIC which says
>  we allocate space for the variable:
>  /* In a VAR_DECL, nonzero means allocate static storage.
>    In a FUNCTION_DECL, nonzero if function has been defined.
>    In a CONSTRUCTOR, nonzero means allocate static storage.
>
>    ??? This is also used in lots of other nodes in unclear ways which
>    should be cleaned up some day.  */
>
>  TREE_STATIC should not be set on those variables as there is no space
>  allocated in the case of the C++ case (I think Ada case also).
>
>  Also "const int conststaticvariable;" in C is global but it will be
>  put in the common section and is called a tentative definition.  So
>  there needs to be another check for that instead of just TREE_PUBLIC.
>  That is if you compile:
>
> const int conststaticvariable;
>
>  int f(void)
>  {
>   return conststaticvariable;
>  }
>  With -fno-common, the tentative definition is no longer one and we
>  should be able to optimize it.
>
>  Thanks,
>  Andrew Pinski
>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gcc-local-3.patch --]
[-- Type: text/x-patch; name=gcc-local-3.patch, Size: 3601 bytes --]

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.

gcc/

2008-03-07  H.J. Lu  <hongjiu.lu@intel.com>

	PR tree-optimization/35494
	* tree-ssa-ccp.c (get_symbol_constant_value): Only fold local
	variables with NULL DECL_INITIAL.

--- gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C.local	2008-03-07 09:28:35.000000000 -0800
+++ gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C	2008-03-07 09:28:35.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 is
+   global.  */
+/* { 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-07 09:28:35.000000000 -0800
+++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-2.c	2008-03-07 09:28:35.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 is
+   global.  */
+/* { 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-07 09:34:05.000000000 -0800
+++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-3.c	2008-03-07 09:57:03.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-07 11:03:04.000000000 -0800
+++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-4.c	2008-03-07 11:02:00.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 is
+   global.  */
+/* { 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-07 10:59:07.000000000 -0800
@@ -306,9 +306,12 @@ get_symbol_constant_value (tree sym)
       if (val
 	  && ccp_decl_initial_min_invariant (val))
 	return val;
-      /* Variables declared 'const' without an initializer
+      /* Local variables declared 'const' without an initializer
 	 have zero as the intializer.  */
       if (!val
+	  && (!TREE_PUBLIC (sym)
+	      || (!DECL_EXTERNAL (sym)
+		  && targetm.binds_local_p (sym)))
           && (INTEGRAL_TYPE_P (TREE_TYPE (sym))
 	       || SCALAR_FLOAT_TYPE_P (TREE_TYPE (sym))))
         return fold_convert (TREE_TYPE (sym), integer_zero_node);

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk
  2008-03-07 19:11   ` H.J. Lu
@ 2008-03-07 22:07     ` H.J. Lu
  2008-03-08 20:44       ` Richard Guenther
  0 siblings, 1 reply; 16+ messages in thread
From: H.J. Lu @ 2008-03-07 22:07 UTC (permalink / raw)
  To: GCC Patches

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?


H.J.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk
  2008-03-07 22:07     ` H.J. Lu
@ 2008-03-08 20:44       ` Richard Guenther
  2008-03-08 23:16         ` H.J. Lu
  0 siblings, 1 reply; 16+ messages in thread
From: Richard Guenther @ 2008-03-08 20:44 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GCC Patches

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.

Thanks,
Richard.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision  132991 breaks 483.xalancbmk
  2008-03-08 20:44       ` Richard Guenther
@ 2008-03-08 23:16         ` H.J. Lu
  2008-03-08 23:32           ` Andrew Pinski
  0 siblings, 1 reply; 16+ messages in thread
From: H.J. Lu @ 2008-03-08 23:16 UTC (permalink / raw)
  To: Richard Guenther; +Cc: GCC Patches

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);
   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);
 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision  132991 breaks 483.xalancbmk
  2008-03-08 23:16         ` H.J. Lu
@ 2008-03-08 23:32           ` Andrew Pinski
  2008-03-08 23:47             ` H.J. Lu
  0 siblings, 1 reply; 16+ messages in thread
From: Andrew Pinski @ 2008-03-08 23:32 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Richard Guenther, GCC Patches



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);
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk
  2008-03-08 23:32           ` Andrew Pinski
@ 2008-03-08 23:47             ` H.J. Lu
  2008-03-09  0:12               ` H.J. Lu
  0 siblings, 1 reply; 16+ messages in thread
From: H.J. Lu @ 2008-03-08 23:47 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: Richard Guenther, GCC Patches

On Sat, Mar 8, 2008 at 3:31 PM, Andrew Pinski <pinskia@gmail.com> wrote:
>
>
>  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.
>
>

Do we have a function which returns if a definition may be overridden
at run-time?

H.J.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision  132991 breaks 483.xalancbmk
  2008-03-08 23:47             ` H.J. Lu
@ 2008-03-09  0:12               ` H.J. Lu
  2008-03-09  5:31                 ` H.J. Lu
  0 siblings, 1 reply; 16+ messages in thread
From: H.J. Lu @ 2008-03-09  0:12 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: Richard Guenther, GCC Patches

On Sat, Mar 08, 2008 at 03:46:38PM -0800, H.J. Lu wrote:
> On Sat, Mar 8, 2008 at 3:31 PM, Andrew Pinski <pinskia@gmail.com> wrote:
> >  This is only true with elf semantics;  mach-o semantics say that a
> >  variable in a shared library is not overwritable.
> >
> >
> 
> Do we have a function which returns if a definition may be overridden
> at run-time?
> 

Here is a patch to modify default_binds_local_p_1 to handle
read-only symbol with initializer.


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: Include "target.h".
	(try_to_simplify):Check if value may be overriden at run time.

	* varasm.c (default_binds_local_p_1): Return false for
	DECL_EXTERNAL only if it isn't read-only with initializer.

	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 16:02:32.000000000 -0800
@@ -1551,7 +1551,9 @@ 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.  */
+      && targetm.binds_local_p (decl))
     return DECL_INITIAL (decl);
   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 16:03:48.000000000 -0800
@@ -300,15 +300,20 @@ 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.  */
+      && targetm.binds_local_p (sym))
     {
       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 16:04:07.000000000 -0800
@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3.  
 #include "params.h"
 #include "tree-ssa-propagate.h"
 #include "tree-ssa-sccvn.h"
+#include "target.h"
 
 /* This algorithm is based on the SCC algorithm presented by Keith
    Cooper and L. Taylor Simpson in "SCC-Based Value numbering"
@@ -1453,6 +1454,8 @@ 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.  */
+	      && targetm.binds_local_p (rhs)
 	      && valid_gimple_expression_p (DECL_INITIAL (rhs)))
 	    return DECL_INITIAL (rhs);
 
--- gcc/varasm.c.local	2007-12-05 17:04:34.000000000 -0800
+++ gcc/varasm.c	2008-03-08 16:01:10.000000000 -0800
@@ -6186,7 +6186,10 @@ default_binds_local_p_1 (const_tree exp,
 	   && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
     local_p = true;
   /* Variables defined outside this object might not be local.  */
-  else if (DECL_EXTERNAL (exp))
+  else if (DECL_EXTERNAL (exp)
+	   && (!TREE_READONLY (exp)
+	       || !TREE_STATIC (exp)
+	       || !DECL_INITIAL (exp)))
     local_p = false;
   /* If defined in this object and visibility is not default, must be
      local.  */

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk
  2008-03-09  0:12               ` H.J. Lu
@ 2008-03-09  5:31                 ` H.J. Lu
  0 siblings, 0 replies; 16+ messages in thread
From: H.J. Lu @ 2008-03-09  5:31 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: Richard Guenther, GCC Patches

On Sat, Mar 8, 2008 at 4:12 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Sat, Mar 08, 2008 at 03:46:38PM -0800, H.J. Lu wrote:
>  > On Sat, Mar 8, 2008 at 3:31 PM, Andrew Pinski <pinskia@gmail.com> wrote:
>
> > >  This is only true with elf semantics;  mach-o semantics say that a
>  > >  variable in a shared library is not overwritable.
>  > >
>  > >
>  >
>  > Do we have a function which returns if a definition may be overridden
>  > at run-time?
>  >
>
>  Here is a patch to modify default_binds_local_p_1 to handle
>  read-only symbol with initializer.
>
>
>
>  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: Include "target.h".
>         (try_to_simplify):Check if value may be overriden at run time.
>
>         * varasm.c (default_binds_local_p_1): Return false for
>         DECL_EXTERNAL only if it isn't read-only with initializer.
>
>
>         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.
>

This patch passes all tests on Linux/ia32, Linux/Intel64 and 483.xalancbmk.

H.J.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision  132991 breaks 483.xalancbmk
  2008-03-07 15:19 ` Richard Guenther
  2008-03-07 15:30   ` H.J. Lu
@ 2008-03-09 14:43   ` H.J. Lu
  2008-03-09 15:47     ` H.J. Lu
  1 sibling, 1 reply; 16+ messages in thread
From: H.J. Lu @ 2008-03-09 14:43 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches

On Fri, Mar 07, 2008 at 04:19:01PM +0100, Richard Guenther wrote:
> On Fri, Mar 7, 2008 at 4:00 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> > We can't fold glocal variables with NULL DECL_INITIAL. I am testing it
> >  on Linux/x86 and Linux/Intel64 as well as 483.xalancbmk. OK to install
> >  if all pass?
> 
> Hm, use targetm.binds_local_p instead?
> 

It turns out that targetm.binds_local_p works since it returns
false for common symbol, even if the symbol may be bound locally
in executable.  I am testing this patch now.


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: Include "target.h".
	(try_to_simplify): Check if value may be overriden at run time.

	* varasm.c (default_binds_local_p_1): Return false for
	DECL_EXTERNAL only if it isn't read-only with initializer.

	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 18:11:53.000000000 -0800
@@ -1551,7 +1551,9 @@ 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.  */
+      && targetm.binds_local_p (decl))
     return DECL_INITIAL (decl);
   return decl;
 }
--- gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C.local	2008-03-08 18:11:53.000000000 -0800
+++ gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C	2008-03-08 18:11:53.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 18:11:53.000000000 -0800
+++ gcc/testsuite/gcc.dg/pr35501-1.c	2008-03-08 18:11:53.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 18:11:53.000000000 -0800
+++ gcc/testsuite/gcc.dg/pr35501-2.c	2008-03-08 18:11:53.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 18:11:53.000000000 -0800
+++ gcc/testsuite/gcc.dg/pr35501-3.c	2008-03-08 18:11:53.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 18:11:53.000000000 -0800
+++ gcc/testsuite/gcc.dg/pr35501-4.c	2008-03-08 18:11:53.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 18:11:53.000000000 -0800
+++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-2.c	2008-03-08 18:11:53.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 18:11:53.000000000 -0800
+++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-3.c	2008-03-08 18:11:53.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 18:11:53.000000000 -0800
+++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-4.c	2008-03-08 18:11:53.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-09 06:58:50.000000000 -0700
@@ -300,7 +300,10 @@ 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
+	 link and run time.  */
+      && targetm.binds_local_p (sym))
     {
       tree val = DECL_INITIAL (sym);
       if (val
--- gcc/tree-ssa-sccvn.c.local	2008-03-08 14:41:18.000000000 -0800
+++ gcc/tree-ssa-sccvn.c	2008-03-08 18:11:53.000000000 -0800
@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3.  
 #include "params.h"
 #include "tree-ssa-propagate.h"
 #include "tree-ssa-sccvn.h"
+#include "target.h"
 
 /* This algorithm is based on the SCC algorithm presented by Keith
    Cooper and L. Taylor Simpson in "SCC-Based Value numbering"
@@ -1453,6 +1454,8 @@ 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.  */
+	      && targetm.binds_local_p (rhs)
 	      && valid_gimple_expression_p (DECL_INITIAL (rhs)))
 	    return DECL_INITIAL (rhs);
 
--- gcc/varasm.c.local	2007-12-05 17:04:34.000000000 -0800
+++ gcc/varasm.c	2008-03-08 18:11:53.000000000 -0800
@@ -6186,7 +6186,10 @@ default_binds_local_p_1 (const_tree exp,
 	   && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
     local_p = true;
   /* Variables defined outside this object might not be local.  */
-  else if (DECL_EXTERNAL (exp))
+  else if (DECL_EXTERNAL (exp)
+	   && (!TREE_READONLY (exp)
+	       || !TREE_STATIC (exp)
+	       || !DECL_INITIAL (exp)))
     local_p = false;
   /* If defined in this object and visibility is not default, must be
      local.  */

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk
  2008-03-09 14:43   ` H.J. Lu
@ 2008-03-09 15:47     ` H.J. Lu
  0 siblings, 0 replies; 16+ messages in thread
From: H.J. Lu @ 2008-03-09 15:47 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches

On Sun, Mar 9, 2008 at 6:43 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Mar 07, 2008 at 04:19:01PM +0100, Richard Guenther wrote:
>
> > On Fri, Mar 7, 2008 at 4:00 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>  > > We can't fold glocal variables with NULL DECL_INITIAL. I am testing it
>  > >  on Linux/x86 and Linux/Intel64 as well as 483.xalancbmk. OK to install
>  > >  if all pass?
>  >
>  > Hm, use targetm.binds_local_p instead?
>  >
>
>  It turns out that targetm.binds_local_p works since it returns
>  false for common symbol, even if the symbol may be bound locally
>  in executable.  I am testing this patch now.

All tests are passed on Linux/x86 and Linux/Intel64 as well as 483.xalancbmk.


H.J.
>
>
>  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: Include "target.h".
>         (try_to_simplify): Check if value may be overriden at run time.
>
>         * varasm.c (default_binds_local_p_1): Return false for
>         DECL_EXTERNAL only if it isn't read-only with initializer.
>
>         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 18:11:53.000000000 -0800
>
> @@ -1551,7 +1551,9 @@ 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.  */
>  +      && targetm.binds_local_p (decl))
>      return DECL_INITIAL (decl);
>    return decl;
>   }
>  --- gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C.local       2008-03-08 18:11:53.000000000 -0800
>  +++ gcc/testsuite/g++.dg/tree-ssa/ssa-store-ccp-1.C     2008-03-08 18:11:53.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 18:11:53.000000000 -0800
>  +++ gcc/testsuite/gcc.dg/pr35501-1.c    2008-03-08 18:11:53.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 18:11:53.000000000 -0800
>  +++ gcc/testsuite/gcc.dg/pr35501-2.c    2008-03-08 18:11:53.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 18:11:53.000000000 -0800
>  +++ gcc/testsuite/gcc.dg/pr35501-3.c    2008-03-08 18:11:53.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 18:11:53.000000000 -0800
>  +++ gcc/testsuite/gcc.dg/pr35501-4.c    2008-03-08 18:11:53.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 18:11:53.000000000 -0800
>  +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-2.c     2008-03-08 18:11:53.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 18:11:53.000000000 -0800
>  +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-3.c     2008-03-08 18:11:53.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 18:11:53.000000000 -0800
>  +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-4.c     2008-03-08 18:11:53.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-09 06:58:50.000000000 -0700
>  @@ -300,7 +300,10 @@ 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
>  +        link and run time.  */
>
> +      && targetm.binds_local_p (sym))
>      {
>        tree val = DECL_INITIAL (sym);
>        if (val
>
> --- gcc/tree-ssa-sccvn.c.local  2008-03-08 14:41:18.000000000 -0800
>  +++ gcc/tree-ssa-sccvn.c        2008-03-08 18:11:53.000000000 -0800
>
> @@ -45,6 +45,7 @@ along with GCC; see the file COPYING3.
>   #include "params.h"
>   #include "tree-ssa-propagate.h"
>   #include "tree-ssa-sccvn.h"
>  +#include "target.h"
>
>   /* This algorithm is based on the SCC algorithm presented by Keith
>     Cooper and L. Taylor Simpson in "SCC-Based Value numbering"
>  @@ -1453,6 +1454,8 @@ 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.  */
>  +             && targetm.binds_local_p (rhs)
>               && valid_gimple_expression_p (DECL_INITIAL (rhs)))
>             return DECL_INITIAL (rhs);
>
>  --- gcc/varasm.c.local  2007-12-05 17:04:34.000000000 -0800
>  +++ gcc/varasm.c        2008-03-08 18:11:53.000000000 -0800
>
>
> @@ -6186,7 +6186,10 @@ default_binds_local_p_1 (const_tree exp,
>            && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
>      local_p = true;
>    /* Variables defined outside this object might not be local.  */
>  -  else if (DECL_EXTERNAL (exp))
>  +  else if (DECL_EXTERNAL (exp)
>  +          && (!TREE_READONLY (exp)
>  +              || !TREE_STATIC (exp)
>  +              || !DECL_INITIAL (exp)))
>      local_p = false;
>    /* If defined in this object and visibility is not default, must be
>       local.  */
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2008-03-09 15:47 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-07 15:00 PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk H.J. Lu
2008-03-07 15:19 ` Richard Guenther
2008-03-07 15:30   ` H.J. Lu
2008-03-07 15:40     ` Richard Guenther
2008-03-09 14:43   ` H.J. Lu
2008-03-09 15:47     ` H.J. Lu
2008-03-07 16:39 ` Andrew Pinski
2008-03-07 17:00 ` Andrew Pinski
2008-03-07 19:11   ` H.J. Lu
2008-03-07 22:07     ` H.J. Lu
2008-03-08 20:44       ` Richard Guenther
2008-03-08 23:16         ` H.J. Lu
2008-03-08 23:32           ` Andrew Pinski
2008-03-08 23:47             ` H.J. Lu
2008-03-09  0:12               ` H.J. Lu
2008-03-09  5:31                 ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).