From patchwork Tue Sep 14 09:22:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Fix PR tree-optimization/45470 From: Ira Rosen X-Patchwork-Id: 64681 Message-Id: To: gcc-patches@gcc.gnu.org Date: Tue, 14 Sep 2010 11:22:19 +0200 Hi, This patch prevents vectorization when one of the statements can throw an exception (it checks only data references and function calls). Bootstrapped (after reverting HJ's patch) with vectorization enabled and tested on x86_64-suse-linux. Committed. Ira ChangeLog: PR tree-optimization/45470 * tree-vect-data-refs.c (vect_analyze_data_refs): Fail if a statement can throw an exception. * tree-vect-stmts.c (vectorizable_call): Likewise. testsuite/ChangeLog: PR tree-optimization/45470 * g++.dg/vect/pr45470-a.cc: New test. * g++.dg/vect/pr45470-b.cc: New test. Index: tree-vect-data-refs.c =================================================================== --- tree-vect-data-refs.c (revision 164269) +++ tree-vect-data-refs.c (working copy) @@ -2542,6 +2542,17 @@ vect_analyze_data_refs (loop_vec_info lo offset = unshare_expr (DR_OFFSET (dr)); init = unshare_expr (DR_INIT (dr)); + if (stmt_could_throw_p (stmt)) + { + if (vect_print_dump_info (REPORT_UNVECTORIZED_LOCATIONS)) + { + fprintf (vect_dump, "not vectorized: statement can throw an " + "exception "); + print_gimple_stmt (vect_dump, stmt, 0, TDF_SLIM); + } + return false; + } + /* Update DR field in stmt_vec_info struct. */ /* If the dataref is in an inner-loop of the loop that is considered for Index: tree-vect-stmts.c =================================================================== --- tree-vect-stmts.c (revision 164269) +++ tree-vect-stmts.c (working copy) @@ -1343,6 +1343,9 @@ vectorizable_call (gimple stmt, gimple_s if (TREE_CODE (gimple_call_lhs (stmt)) != SSA_NAME) return false; + if (stmt_could_throw_p (stmt)) + return false; + vectype_out = STMT_VINFO_VECTYPE (stmt_info); /* Process function arguments. */ Index: testsuite/g++.dg/vect/pr45470-a.cc =================================================================== --- testsuite/g++.dg/vect/pr45470-a.cc (revision 0) +++ testsuite/g++.dg/vect/pr45470-a.cc (revision 0) @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -ftree-vectorize -fno-vect-cost-model -fnon-call-exceptions" } */ + +struct A +{ + A (): a (0), b (0), c (0) + { + }; + ~A (); + int a, b, c; +}; + +struct B +{ + B (); + A a1; + A a2; +}; + +B::B () +{ +} + +/* { dg-final { cleanup-tree-dump "vect" } } */ Index: testsuite/g++.dg/vect/pr45470-b.cc =================================================================== --- testsuite/g++.dg/vect/pr45470-b.cc (revision 0) +++ testsuite/g++.dg/vect/pr45470-b.cc (revision 0) @@ -0,0 +1,52 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -ftree-vectorize -fno-vect-cost-model -fnon-call-exceptions" } */ + +template < typename _Tp > struct new_allocator +{ + typedef _Tp * pointer; + template < typename > struct rebind + { + typedef new_allocator other; + }; + +}; + +template < typename _Tp > struct allocator:public new_allocator < _Tp > +{}; + +template < typename _Tp, typename _Alloc > struct _Vector_base +{ + typedef typename _Alloc::template rebind < _Tp >::other _Tp_alloc_type; + struct + { + typename _Tp_alloc_type::pointer _M_start; + typename _Tp_alloc_type::pointer _M_finish; + typename _Tp_alloc_type::pointer _M_end_of_storage; + }; + +}; + +template + < + typename + _Tp, + typename + _Alloc = allocator < _Tp > >struct vector:_Vector_base < _Tp, _Alloc > +{ + typedef _Vector_base < _Tp, _Alloc > _Base; + vector ():_Base () + {} + ~vector (); +} +; +struct LoadGraph +{ + LoadGraph (int); + vector < struct _GdkColor >colors; + vector < float >data_block; +}; + +LoadGraph::LoadGraph (int) +{} + +/* { dg-final { cleanup-tree-dump "vect" } } */