This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]