]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/56098 (conditional write through volatile pointer produces...
authorJakub Jelinek <jakub@redhat.com>
Wed, 3 Apr 2013 18:02:57 +0000 (20:02 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 3 Apr 2013 18:02:57 +0000 (20:02 +0200)
Backported from mainline
2013-01-25  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/56098
* tree-ssa-phiopt.c (nt_init_block): Don't call add_or_mark_expr
for stmts with volatile ops.
(cond_store_replacement): Don't optimize if assign has volatile ops.
(cond_if_else_store_replacement_1): Don't optimize if either
then_assign or else_assign have volatile ops.

* gcc.dg/pr56098-1.c: New test.

From-SVN: r197449

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr56098-1.c [new file with mode: 0644]
gcc/tree-ssa-phiopt.c

index 2593b4cac4d0dfee9500eb1204c4f5368e0f0962..3ff897fb851c76b04e6d485c73bf3785000b2323 100644 (file)
@@ -1,6 +1,15 @@
 2013-04-03  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2013-01-25  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/56098
+       * tree-ssa-phiopt.c (nt_init_block): Don't call add_or_mark_expr
+       for stmts with volatile ops.
+       (cond_store_replacement): Don't optimize if assign has volatile ops.
+       (cond_if_else_store_replacement_1): Don't optimize if either
+       then_assign or else_assign have volatile ops.
+
        2013-01-18  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/56015
index 47e2801707431688a5b6e99884bd9dd6021b1586..c227cc1e2d17a201c353ac9d6c26c59b5fa7ff8b 100644 (file)
@@ -1,6 +1,11 @@
 2013-04-03  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2013-01-25  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/56098
+       * gcc.dg/pr56098-1.c: New test.
+
        2013-01-18  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/56015
diff --git a/gcc/testsuite/gcc.dg/pr56098-1.c b/gcc/testsuite/gcc.dg/pr56098-1.c
new file mode 100644 (file)
index 0000000..c3b081a
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR tree-optimization/56098 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+volatile int *p;
+
+void
+foo (int x)
+{
+  *p = 1;
+  if (x)
+    *p = 2;
+}
+
+/* { dg-final { scan-tree-dump-not "=\[^\n\r]*\\*p" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
index af221ed6a45f73d9f48b3c28c1e3a066ed424285..37f2dbb7f3eb24ec1d0d3b0fa0aa098a223e78f7 100644 (file)
@@ -1160,7 +1160,7 @@ nt_init_block (struct dom_walk_data *data ATTRIBUTE_UNUSED, basic_block bb)
     {
       gimple stmt = gsi_stmt (gsi);
 
-      if (gimple_assign_single_p (stmt))
+      if (gimple_assign_single_p (stmt) && !gimple_has_volatile_ops (stmt))
        {
          add_or_mark_expr (bb, gimple_assign_lhs (stmt), nontrap_set, true);
          add_or_mark_expr (bb, gimple_assign_rhs1 (stmt), nontrap_set, false);
@@ -1237,7 +1237,8 @@ cond_store_replacement (basic_block middle_bb, basic_block join_bb,
 
   /* Check if middle_bb contains of only one store.  */
   if (!assign
-      || !gimple_assign_single_p (assign))
+      || !gimple_assign_single_p (assign)
+      || gimple_has_volatile_ops (assign))
     return false;
 
   locus = gimple_location (assign);
@@ -1333,8 +1334,10 @@ cond_if_else_store_replacement (basic_block then_bb, basic_block else_bb,
   /* Check if then_bb and else_bb contain only one store each.  */
   if (then_assign == NULL
       || !gimple_assign_single_p (then_assign)
+      || gimple_has_volatile_ops (then_assign)
       || else_assign == NULL
-      || !gimple_assign_single_p (else_assign))
+      || !gimple_assign_single_p (else_assign)
+      || gimple_has_volatile_ops (else_assign))
     return false;
 
   lhs = gimple_assign_lhs (then_assign);