+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
+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.
--- /dev/null
+/* { 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" } } */
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" } } */
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))
if (t)
{
+ /* Preserve volatileness of the original expression. */
+ TREE_THIS_VOLATILE (t) = volatile_p;
*expr_p = t;
*changed_p = true;
}
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))
{