From 2e58df6ecf3d060e3a8bd95f898baf89f733e1f5 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Fri, 15 Feb 2008 15:24:19 +0000 Subject: re PR tree-optimization/35164 (Unable to coalesce ab SSA_NAMEs) 2008-02-15 Richard Guenther Zdenek Dvorak PR tree-optimization/35164 * tree-flow.h (stmt_references_abnormal_ssa_name): Declare. * tree-dfa.c (stmt_references_abnormal_ssa_name): New function. * tree-ssa-forwprop.c (tree_ssa_forward_propagate_single_use_vars): Only propagate addresses which do not have abnormal SSA_NAMEs in their operands. * g++.dg/torture/pr35164-1.C: New testcase. * g++.dg/torture/pr35164-2.C: Likewise. Co-Authored-By: Zdenek Dvorak From-SVN: r132345 --- gcc/ChangeLog | 10 +++++ gcc/testsuite/ChangeLog | 7 ++++ gcc/testsuite/g++.dg/torture/pr35164-1.C | 69 ++++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/torture/pr35164-2.C | 27 +++++++++++++ gcc/tree-dfa.c | 18 +++++++++ gcc/tree-flow.h | 1 + gcc/tree-ssa-forwprop.c | 3 +- 7 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/torture/pr35164-1.C create mode 100644 gcc/testsuite/g++.dg/torture/pr35164-2.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a82c143..b3075a6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2008-02-15 Richard Guenther + Zdenek Dvorak + + PR tree-optimization/35164 + * tree-flow.h (stmt_references_abnormal_ssa_name): Declare. + * tree-dfa.c (stmt_references_abnormal_ssa_name): New function. + * tree-ssa-forwprop.c (tree_ssa_forward_propagate_single_use_vars): + Only propagate addresses which do not have abnormal SSA_NAMEs + in their operands. + 2008-02-15 Joseph Myers PR target/35088 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 26b41f8..f5ec2de 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2008-02-15 Richard Guenther + Zdenek Dvorak + + PR tree-optimization/35164 + * g++.dg/torture/pr35164-1.C: New testcase. + * g++.dg/torture/pr35164-2.C: Likewise. + 2008-02-15 Dominique d'Humieres PR testsuite/35119 diff --git a/gcc/testsuite/g++.dg/torture/pr35164-1.C b/gcc/testsuite/g++.dg/torture/pr35164-1.C new file mode 100644 index 0000000..1704c22 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr35164-1.C @@ -0,0 +1,69 @@ +typedef __SIZE_TYPE__ size_t; +template class __normal_iterator { +public: + const _Iterator& base() const; +}; +template inline +void copy_backward(_BI1 __first, _BI1 __last, _BI2 __result) { + while (__first != __last) *--__result = *--__last; +} +template struct _Vector_base { + struct _Vector_impl { _Tp* _M_finish; }; + _Vector_impl _M_impl; +}; +template class vector : protected _Vector_base<_Tp> { + typedef vector<_Tp> vector_type; + typedef _Tp * pointer; + typedef _Tp & reference; + typedef __normal_iterator iterator; + typedef size_t size_type; +public: + iterator end(); + void resize(size_type __new_size) { insert(end(), __new_size); } + reference operator[](size_type __n); + void insert(iterator __position, size_type __n) + { + pointer __old_finish(this->_M_impl._M_finish); + copy_backward(__position.base(), __old_finish - __n, __old_finish); + } +}; +struct A { + virtual ~A (); + void incRef (); + void decRef (); +}; +struct C : public A { + static C *alloc (); +}; +template struct B { + B () : ptr (T::alloc ()) { } + B (T *a_ptr) : ptr (a_ptr) { } + ~B () { decRef (); } + B& operator= (const B& a) { if (a.get () != this->get ()) { decRef (); +incRef (); } } + template operator B () const { return B (ptr); } + T* operator-> () const { } + T* get () const { return ptr; } + void decRef () const { if (ptr != 0) ptr->decRef (); } + void incRef () const { if (ptr != 0) ptr->incRef (); } + T *ptr; +}; +struct D : public C { + template inline void foo (const B & x) { d.resize (1); d[0] = x; +} + vector > d; +}; +struct E : public C { + static E *alloc (); +}; +struct F : public D { + static F *alloc (); +}; +void foo (vector > & x) { + for (int i = 0; i < 2; ++i) + { + B l; + B m; + l->foo (m); + } +} diff --git a/gcc/testsuite/g++.dg/torture/pr35164-2.C b/gcc/testsuite/g++.dg/torture/pr35164-2.C new file mode 100644 index 0000000..463cad7 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr35164-2.C @@ -0,0 +1,27 @@ +struct __shared_count { + __shared_count() { _M_pi = new int; } + int * _M_pi; +}; +template +class __shared_ptr { +public: + __shared_ptr(_Tp* __p); + void reset(int * __p) { + __shared_ptr(__p).swap(*this); + } + void swap(__shared_ptr<_Tp>& __other) { + __other._M_refcount._M_pi = _M_refcount._M_pi; + } + __shared_count _M_refcount; +}; +template class shared_ptr : public __shared_ptr<_Tp> {}; +int main() { + for (shared_ptr *iter;;) + { + try { + (iter++)->reset(new int); + } + catch (...) { + } + } +} diff --git a/gcc/tree-dfa.c b/gcc/tree-dfa.c index f79df0b..346f6f3 100644 --- a/gcc/tree-dfa.c +++ b/gcc/tree-dfa.c @@ -1028,3 +1028,21 @@ get_ref_base_and_extent (tree exp, HOST_WIDE_INT *poffset, return exp; } +/* Returns true if STMT references an SSA_NAME that has + SSA_NAME_OCCURS_IN_ABNORMAL_PHI set, otherwise false. */ + +bool +stmt_references_abnormal_ssa_name (tree stmt) +{ + ssa_op_iter oi; + use_operand_p use_p; + + FOR_EACH_SSA_USE_OPERAND (use_p, stmt, oi, SSA_OP_USE) + { + if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (USE_FROM_PTR (use_p))) + return true; + } + + return false; +} + diff --git a/gcc/tree-flow.h b/gcc/tree-flow.h index adc2508..286c60b 100644 --- a/gcc/tree-flow.h +++ b/gcc/tree-flow.h @@ -822,6 +822,7 @@ extern void find_new_referenced_vars (tree *); extern tree make_rename_temp (tree, const char *); extern void set_default_def (tree, tree); extern tree gimple_default_def (struct function *, tree); +extern bool stmt_references_abnormal_ssa_name (tree); /* In tree-phinodes.c */ extern void reserve_phi_args_for_new_edge (basic_block); diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index 2da17c8..91bd617 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -968,7 +968,8 @@ tree_ssa_forward_propagate_single_use_vars (void) && types_compatible_p (TREE_TYPE (TREE_TYPE (TREE_OPERAND (rhs, 0))), TREE_TYPE (TREE_TYPE (rhs))))) { - if (forward_propagate_addr_expr (lhs, rhs)) + if (!stmt_references_abnormal_ssa_name (stmt) + && forward_propagate_addr_expr (lhs, rhs)) { release_defs (stmt); todoflags |= TODO_remove_unused_locals; -- cgit v1.1