This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: PR tree-optimization/35494: [4.4 Regression]: Revision 132991 breaks 483.xalancbmk
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. */