summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2011-12-31 23:53:57 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2011-12-31 23:53:57 +0000
commit3064bb7bdf4b3e57842207a7cfbb72d686ace48a (patch)
treeeae0d52d578dbcd38c56a08992fb9bb1ddb7b2ac
parent8081d3a635c46337db187a9f6971e707986bf1a8 (diff)
downloadgcc-3064bb7bdf4b3e57842207a7cfbb72d686ace48a.tar.gz
PR tree-optimization/51683
* tree-ssa-propagate.c (substitute_and_fold): Don't optimize away calls with side-effects. * tree-ssa-ccp.c (ccp_fold_stmt): Likewise. * gcc.dg/pr51683.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@182761 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/pr51683.c18
-rw-r--r--gcc/tree-ssa-ccp.c8
-rw-r--r--gcc/tree-ssa-propagate.c8
5 files changed, 43 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index bf05b56b77b..fec1dec2221 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2012-01-01 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/51683
+ * tree-ssa-propagate.c (substitute_and_fold): Don't optimize away
+ calls with side-effects.
+ * tree-ssa-ccp.c (ccp_fold_stmt): Likewise.
+
2011-12-31 Alexandre Oliva <aoliva@redhat.com>
* cselib.h (cselib_add_permanent_equiv): Declare.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b1b7e370588..6e814141275 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2012-01-01 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/51683
+ * gcc.dg/pr51683.c: New test.
+
2011-12-31 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/51397
diff --git a/gcc/testsuite/gcc.dg/pr51683.c b/gcc/testsuite/gcc.dg/pr51683.c
new file mode 100644
index 00000000000..f5a4a8be485
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr51683.c
@@ -0,0 +1,18 @@
+/* PR tree-optimization/51683 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+static inline void *
+bar (void *p, void *q, int r)
+{
+ return __builtin_memcpy (p, q, r);
+}
+
+void *
+foo (void *p)
+{
+ return bar ((void *) 0x12345000, p, 256);
+}
+
+/* { dg-final { scan-tree-dump "memcpy" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
index a9c38ee8fad..738606fad02 100644
--- a/gcc/tree-ssa-ccp.c
+++ b/gcc/tree-ssa-ccp.c
@@ -1,6 +1,6 @@
/* Conditional constant propagation pass for the GNU compiler.
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
- 2010, 2011 Free Software Foundation, Inc.
+ 2010, 2011, 2012 Free Software Foundation, Inc.
Adapted from original RTL SSA-CCP by Daniel Berlin <dberlin@dberlin.org>
Adapted to GIMPLE trees by Diego Novillo <dnovillo@redhat.com>
@@ -1878,6 +1878,7 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi)
case GIMPLE_CALL:
{
tree lhs = gimple_call_lhs (stmt);
+ int flags = gimple_call_flags (stmt);
tree val;
tree argt;
bool changed = false;
@@ -1888,7 +1889,10 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi)
type issues. */
if (lhs
&& TREE_CODE (lhs) == SSA_NAME
- && (val = get_constant_value (lhs)))
+ && (val = get_constant_value (lhs))
+ /* Don't optimize away calls that have side-effects. */
+ && (flags & (ECF_CONST|ECF_PURE)) != 0
+ && (flags & ECF_LOOPING_CONST_OR_PURE) == 0)
{
tree new_rhs = unshare_expr (val);
bool res;
diff --git a/gcc/tree-ssa-propagate.c b/gcc/tree-ssa-propagate.c
index 80b33e11d80..a057ad72bed 100644
--- a/gcc/tree-ssa-propagate.c
+++ b/gcc/tree-ssa-propagate.c
@@ -1,5 +1,5 @@
/* Generic SSA value propagation engine.
- Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+ Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Free Software Foundation, Inc.
Contributed by Diego Novillo <dnovillo@redhat.com>
@@ -1056,6 +1056,12 @@ substitute_and_fold (ssa_prop_get_value_fn get_value_fn,
}
else if (is_gimple_call (def_stmt))
{
+ int flags = gimple_call_flags (def_stmt);
+
+ /* Don't optimize away calls that have side-effects. */
+ if ((flags & (ECF_CONST|ECF_PURE)) == 0
+ || (flags & ECF_LOOPING_CONST_OR_PURE))
+ continue;
if (update_call_from_tree (&gsi, val)
&& maybe_clean_or_replace_eh_stmt (def_stmt, gsi_stmt (gsi)))
gimple_purge_dead_eh_edges (gimple_bb (gsi_stmt (gsi)));