2007-07-13 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 13 Jul 2007 15:41:02 +0000 (15:41 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 13 Jul 2007 15:41:02 +0000 (15:41 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@126624 138bc75d-0d04-0410-961f-82ee72b054a4

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 49d10e0..5c8b8be 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 666adc2..469fe0f 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 272a4f8..93345a9 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 1e9dde7..b0c3b95 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)
          {