aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2011-11-28 22:03:11 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2011-11-28 22:03:11 +0100
commit8c29866f7fab248c5f3bfba80399c2f462236f2a (patch)
tree32e3db64b2d2968a496e87e98982ff6eb23b7915
parent99d8763e19ee7949d3afee72f07612ebb3bf37f8 (diff)
downloadgcc-8c29866f7fab248c5f3bfba80399c2f462236f2a.zip
gcc-8c29866f7fab248c5f3bfba80399c2f462236f2a.tar.gz
gcc-8c29866f7fab248c5f3bfba80399c2f462236f2a.tar.bz2
re PR tree-optimization/50078 (combine wrong code: volatile accesses optimized out)
PR tree-optimization/50078 * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Copy over TREE_THIS_VOLATILE also from the old to new lhs resp. rhs. * gcc.dg/pr50078.c: New test. From-SVN: r181786
-rw-r--r--gcc/ChangeLog4
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/gcc.dg/pr50078.c14
-rw-r--r--gcc/tree-ssa-forwprop.c14
4 files changed, 29 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a2b33de..c66ec82 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,9 @@
2011-11-28 Jakub Jelinek <jakub@redhat.com>
+ PR tree-optimization/50078
+ * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Copy over
+ TREE_THIS_VOLATILE also from the old to new lhs resp. rhs.
+
PR tree-optimization/50682
* tree-eh.c (maybe_remove_unreachable_handlers): New function.
* tree-flow.h (maybe_remove_unreachable_handlers): New prototype.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 72c3fac..ee4a714 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
2011-11-28 Jakub Jelinek <jakub@redhat.com>
+ PR tree-optimization/50078
+ * gcc.dg/pr50078.c: New test.
+
PR tree-optimization/50682
* g++.dg/opt/pr50682.C: New test.
diff --git a/gcc/testsuite/gcc.dg/pr50078.c b/gcc/testsuite/gcc.dg/pr50078.c
new file mode 100644
index 0000000..a8aee43
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr50078.c
@@ -0,0 +1,14 @@
+/* PR tree-optimization/50078 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+unsigned nonvolvar[2];
+
+void
+test (int arg)
+{
+ unsigned v = *(volatile unsigned *) (&nonvolvar[arg]);
+ *(volatile unsigned *) (&nonvolvar[arg]) = v;
+}
+
+/* { dg-final { scan-assembler-times "movl\[^\n\r\]*nonvolvar" 2 { target { { i?86-*-* x86_64-*-* } && nonpic } } } } */
diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c
index d707db5..6ab4731 100644
--- a/gcc/tree-ssa-forwprop.c
+++ b/gcc/tree-ssa-forwprop.c
@@ -910,7 +910,7 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs,
TREE_TYPE (gimple_assign_rhs1 (use_stmt))))
{
tree *def_rhs_basep = &TREE_OPERAND (def_rhs, 0);
- tree new_offset, new_base, saved;
+ tree new_offset, new_base, saved, new_lhs;
while (handled_component_p (*def_rhs_basep))
def_rhs_basep = &TREE_OPERAND (*def_rhs_basep, 0);
saved = *def_rhs_basep;
@@ -930,8 +930,9 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs,
new_base, new_offset);
TREE_THIS_VOLATILE (*def_rhs_basep) = TREE_THIS_VOLATILE (lhs);
TREE_THIS_NOTRAP (*def_rhs_basep) = TREE_THIS_NOTRAP (lhs);
- gimple_assign_set_lhs (use_stmt,
- unshare_expr (TREE_OPERAND (def_rhs, 0)));
+ new_lhs = unshare_expr (TREE_OPERAND (def_rhs, 0));
+ gimple_assign_set_lhs (use_stmt, new_lhs);
+ TREE_THIS_VOLATILE (new_lhs) = TREE_THIS_VOLATILE (lhs);
*def_rhs_basep = saved;
tidy_after_forward_propagate_addr (use_stmt);
/* Continue propagating into the RHS if this was not the
@@ -991,7 +992,7 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs,
TREE_TYPE (TREE_OPERAND (def_rhs, 0))))
{
tree *def_rhs_basep = &TREE_OPERAND (def_rhs, 0);
- tree new_offset, new_base, saved;
+ tree new_offset, new_base, saved, new_rhs;
while (handled_component_p (*def_rhs_basep))
def_rhs_basep = &TREE_OPERAND (*def_rhs_basep, 0);
saved = *def_rhs_basep;
@@ -1011,8 +1012,9 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs,
new_base, new_offset);
TREE_THIS_VOLATILE (*def_rhs_basep) = TREE_THIS_VOLATILE (rhs);
TREE_THIS_NOTRAP (*def_rhs_basep) = TREE_THIS_NOTRAP (rhs);
- gimple_assign_set_rhs1 (use_stmt,
- unshare_expr (TREE_OPERAND (def_rhs, 0)));
+ new_rhs = unshare_expr (TREE_OPERAND (def_rhs, 0));
+ gimple_assign_set_rhs1 (use_stmt, new_rhs);
+ TREE_THIS_VOLATILE (new_rhs) = TREE_THIS_VOLATILE (rhs);
*def_rhs_basep = saved;
fold_stmt_inplace (use_stmt_gsi);
tidy_after_forward_propagate_addr (use_stmt);