aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/tree-ssa/pr33604.C46
-rw-r--r--gcc/testsuite/gcc.dg/pr32721.c3
-rw-r--r--gcc/tree-ssa-ccp.c3
-rw-r--r--gcc/tree-ssa-forwprop.c10
6 files changed, 75 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d4e13bd..ce33a5b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2007-11-09 Richard Guenther <rguenther@suse.de>
+
+ PR tree-optimization/33604
+ * tree-ssa-forwprop.c (tree_ssa_forward_propagate_single_use_vars):
+ Disregard changes in CV qualifiers of pointed to types for
+ forward propagating ADDR_EXPRs.
+ * tree-ssa-ccp.c (fold_stmt_r): Preserve volatileness of the original
+ expression.
+
2007-11-09 Richard Sandiford <rsandifo@nildram.co.uk>
* dse.c (find_shift_sequence): Always choose an integer mode for
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0f31de0..5cb97b9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2007-11-09 Richard Guenther <rguenther@suse.de>
+
+ PR tree-optimization/33604
+ * g++.dg/tree-ssa/pr33604.C: New testcase.
+ * gcc.dg/pr32721.c: Adjust pattern.
+
2007-11-09 Richard Sandiford <rsandifo@nildram.co.uk>
* gcc.target/mips/dse-1.c: Disable.
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr33604.C b/gcc/testsuite/g++.dg/tree-ssa/pr33604.C
new file mode 100644
index 0000000..d780062
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/pr33604.C
@@ -0,0 +1,46 @@
+/* { dg-do run } */
+/* { dg-options "-O -fdump-tree-forwprop1" } */
+
+struct Value
+{
+ double value;
+ Value(double value_) : value (value_) {}
+ operator double() const { return value; }
+ Value& operator=(double other) { value = other; }
+};
+
+struct Ref
+{
+ const Value& m;
+ Ref(const Value& m_) : m(m_) {}
+ operator double() const { return m; }
+};
+
+struct Diff
+{
+ const Ref lhs, rhs;
+ Diff(const Value& lhs_, const Value& rhs_) : lhs(lhs_), rhs(rhs_) {}
+ operator double() const { return lhs - rhs; }
+};
+
+extern "C" void abort (void);
+int main(int argc, char *argv[])
+{
+ Value I(1), m(4);
+ for(int a = 0; a < 1000; a++)
+ m = Diff (I, m);
+
+ if (!(m / 4 == I))
+ abort ();
+ return 0;
+}
+
+/* Check that we forward propagated
+ D.2182_13 = (struct Ref *) &D.2137.lhs;
+ to
+ D.2182_13->lhs.m ={v} &I;
+ yielding
+ D.2137.lhs.m ={v} &I; */
+
+/* { dg-final { scan-tree-dump-times "D\\\.....\\\..hs\\\.m =" 2 "forwprop1" } } */
+/* { dg-final { cleanup-tree-dump "forwprop1" } } */
diff --git a/gcc/testsuite/gcc.dg/pr32721.c b/gcc/testsuite/gcc.dg/pr32721.c
index 2f3a18a..b62272b 100644
--- a/gcc/testsuite/gcc.dg/pr32721.c
+++ b/gcc/testsuite/gcc.dg/pr32721.c
@@ -14,5 +14,6 @@ spinlock1 = &spinlock[1];
while (*spinlock0);
}
-/* { dg-final { scan-tree-dump "={v} \\*spinlock0" "optimized" } } */
+/* { dg-final { scan-tree-dump "={v} .*spinlock" "optimized" } } */
+/* { dg-final { scan-tree-dump "spinlock.* ={v}" "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
index 05a65f6..301316d 100644
--- a/gcc/tree-ssa-ccp.c
+++ b/gcc/tree-ssa-ccp.c
@@ -2034,6 +2034,7 @@ fold_stmt_r (tree *expr_p, int *walk_subtrees, void *data)
bool *inside_addr_expr_p = fold_stmt_r_data->inside_addr_expr_p;
bool *changed_p = fold_stmt_r_data->changed_p;
tree expr = *expr_p, t;
+ bool volatile_p = TREE_THIS_VOLATILE (expr);
/* ??? It'd be nice if walk_tree had a pre-order option. */
switch (TREE_CODE (expr))
@@ -2159,6 +2160,8 @@ fold_stmt_r (tree *expr_p, int *walk_subtrees, void *data)
if (t)
{
+ /* Preserve volatileness of the original expression. */
+ TREE_THIS_VOLATILE (t) = volatile_p;
*expr_p = t;
*changed_p = true;
}
diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c
index 047d057..bacd34e 100644
--- a/gcc/tree-ssa-forwprop.c
+++ b/gcc/tree-ssa-forwprop.c
@@ -952,7 +952,15 @@ tree_ssa_forward_propagate_single_use_vars (void)
continue;
}
- if (TREE_CODE (rhs) == ADDR_EXPR)
+ if (TREE_CODE (rhs) == ADDR_EXPR
+ /* We can also disregard changes in CV qualifiers for
+ the dereferenced value. */
+ || ((TREE_CODE (rhs) == NOP_EXPR
+ || TREE_CODE (rhs) == CONVERT_EXPR)
+ && TREE_CODE (TREE_OPERAND (rhs, 0)) == ADDR_EXPR
+ && POINTER_TYPE_P (TREE_TYPE (rhs))
+ && useless_type_conversion_p (TREE_TYPE (TREE_TYPE (rhs)),
+ TREE_TYPE (TREE_TYPE (TREE_OPERAND (rhs, 0))))))
{
if (forward_propagate_addr_expr (lhs, rhs))
{