re PR tree-optimization/32721 (CCP removes volatile qualifiers.)
authorRichard Guenther <rguenther@suse.de>
Fri, 13 Jul 2007 15:41:02 +0000 (15:41 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 13 Jul 2007 15:41:02 +0000 (15:41 +0000)
2007-07-13  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/32721
* tree-ssa-ccp.c (maybe_fold_stmt_indirect): Preserve
TREE_THIS_VOLATILE on the folded reference.
* tree-ssa-operands.c (get_expr_operands): Set has_volatile_ops
if the array reference has TREE_THIS_VOLATILE set.

* gcc.dg/pr32721.c: New testcase.

From-SVN: r126624

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr32721.c [new file with mode: 0644]
gcc/tree-ssa-ccp.c
gcc/tree-ssa-operands.c

index 49d10e0d5a700c86794abf3251dea63e542d61f9..5c8b8bed07b5e5da985be2b13e73c5d27c2ba04b 100644 (file)
@@ -1,3 +1,11 @@
+2007-07-13  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/32721
+       * tree-ssa-ccp.c (maybe_fold_stmt_indirect): Preserve
+       TREE_THIS_VOLATILE on the folded reference.
+       * tree-ssa-operands.c (get_expr_operands): Set has_volatile_ops
+       if the array reference has TREE_THIS_VOLATILE set.
+
 2007-07-13  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR other/32188
index 666adc273044a211d7ca8921aafa925cfc588108..469fe0f2dfe33b0aa91ab12e1f7f14a38be8be39 100644 (file)
@@ -1,3 +1,8 @@
+2007-07-13  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/32721
+       * gcc.dg/pr32721.c: New testcase.
+
 2007-07-13  Hans-Peter Nilsson  <hp@axis.com>
 
        * gcc.dg/20011127-1.c: Use dg-message, not dg-error to match the
diff --git a/gcc/testsuite/gcc.dg/pr32721.c b/gcc/testsuite/gcc.dg/pr32721.c
new file mode 100644 (file)
index 0000000..392937e
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int spinlock[2];
+int main ()
+{
+volatile int * spinlock0;
+volatile int * spinlock1;
+spinlock0 = &spinlock[0];
+spinlock1 = &spinlock[1];
+
+*spinlock0 = 0;
+*spinlock1 = 0;
+ while (*spinlock0);
+}
+
+/* { dg-final { scan-tree-dump "= spinlock.0." "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
index 272a4f857414a25e9fab1242ac47d5ed829d67e1..93345a99ccc17b6069093f017ae219db8aa75a14 100644 (file)
@@ -1839,6 +1839,7 @@ static tree
 maybe_fold_stmt_indirect (tree expr, tree base, tree offset)
 {
   tree t;
+  bool volatile_p = TREE_THIS_VOLATILE (expr);
 
   /* We may well have constructed a double-nested PLUS_EXPR via multiple
      substitutions.  Fold that down to one.  Remove NON_LVALUE_EXPRs that
@@ -1882,7 +1883,10 @@ maybe_fold_stmt_indirect (tree expr, tree base, tree offset)
       t = maybe_fold_offset_to_reference (base_addr, offset,
                                          TREE_TYPE (expr));
       if (t)
-       return t;
+       {
+         TREE_THIS_VOLATILE (t) = volatile_p;
+         return t;
+       }
     }
   else
     {
index 1e9dde7e327017243431e400962a957c47b24faa..b0c3b9589b850febfef05738d5e08fa31ae74d69 100644 (file)
@@ -2078,6 +2078,9 @@ get_expr_operands (tree stmt, tree *expr_p, int flags)
 
            if (!none)
              flags |= opf_no_vops;
+
+           if (TREE_THIS_VOLATILE (expr))
+             get_stmt_ann (stmt)->has_volatile_ops = true;
          }
        else if (TREE_CODE (ref) == INDIRECT_REF)
          {