From 15b8646e2be52c6e63e48a62477759fe49fa19d2 Mon Sep 17 00:00:00 2001 From: spop Date: Thu, 14 Jan 2010 08:15:09 +0000 Subject: [PATCH] Fix PR42681. 2010-01-14 Sebastian Pop PR middle-end/42681 * graphite-clast-to-gimple.c (gloog_error): New static variable. (clast_to_gcc_expression): Do not build MULT_EXPR of POINTER_TYPE_P. Set gloog_error when such an expression failed to be built. (translate_clast): Early return when gloog_error is set. (gloog): Clear gloog_error. When gloog_error is set, call set_ifsese_condition to enable the original code. Return the status of the code generation based on gloog_error. * sese.c (set_ifsese_condition): New. * sese.h (set_ifsese_condition): Declared. * testsuite/g++.dg/graphite/pr42681.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/graphite@155883 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog.graphite | 15 +++++++++++++++ gcc/graphite-clast-to-gimple.c | 18 +++++++++++++++--- gcc/sese.c | 28 ++++++++++++++++++++++++++++ gcc/sese.h | 1 + gcc/testsuite/g++.dg/graphite/pr42681.C | 17 +++++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/graphite/pr42681.C diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite index 8b316b17696..f90d5d59d4c 100644 --- a/gcc/ChangeLog.graphite +++ b/gcc/ChangeLog.graphite @@ -1,5 +1,20 @@ 2010-01-14 Sebastian Pop + PR middle-end/42681 + * graphite-clast-to-gimple.c (gloog_error): New static variable. + (clast_to_gcc_expression): Do not build MULT_EXPR of POINTER_TYPE_P. + Set gloog_error when such an expression failed to be built. + (translate_clast): Early return when gloog_error is set. + (gloog): Clear gloog_error. When gloog_error is set, call + set_ifsese_condition to enable the original code. Return the status + of the code generation based on gloog_error. + * sese.c (set_ifsese_condition): New. + * sese.h (set_ifsese_condition): Declared. + + * testsuite/g++.dg/graphite/pr42681.C: New. + +2010-01-14 Sebastian Pop + PR middle-end/42732 * graphite-clast-to-gimple.c (gloog): Call scev_reset_htab and rename_nb_iterations. diff --git a/gcc/graphite-clast-to-gimple.c b/gcc/graphite-clast-to-gimple.c index be16807872c..6651e95b48f 100644 --- a/gcc/graphite-clast-to-gimple.c +++ b/gcc/graphite-clast-to-gimple.c @@ -52,6 +52,10 @@ along with GCC; see the file COPYING3. If not see #include "graphite-clast-to-gimple.h" #include "graphite-dependences.h" +/* This flag is set when an error occurred during the translation of + CLAST to Gimple. */ +static bool gloog_error; + /* Verifies properties that GRAPHITE should maintain during translation. */ static inline void @@ -294,7 +298,11 @@ clast_to_gcc_expression (tree type, struct clast_expr *e, newivs_index, params_index); tree cst = gmp_cst_to_tree (type, t->val); name = fold_convert (type, name); - return fold_build2 (MULT_EXPR, type, cst, name); + if (!POINTER_TYPE_P (type)) + return fold_build2 (MULT_EXPR, type, cst, name); + + gloog_error = true; + return cst; } } else @@ -944,7 +952,7 @@ translate_clast (sese region, loop_p context_loop, struct clast_stmt *stmt, htab_t newivs_index, htab_t bb_pbb_mapping, int level, htab_t params_index) { - if (!stmt) + if (!stmt || gloog_error) return next_e; if (CLAST_STMT_IS_A (stmt, stmt_root)) @@ -1431,6 +1439,7 @@ gloog (scop_p scop, htab_t bb_pbb_mapping) cloog_prog_clast pc; timevar_push (TV_GRAPHITE_CODE_GEN); + gloog_error = false; pc = scop_to_clast (scop); @@ -1476,6 +1485,9 @@ gloog (scop_p scop, htab_t bb_pbb_mapping) recompute_all_dominators (); graphite_verify (); + if (gloog_error) + set_ifsese_condition (if_region, integer_zero_node); + free (if_region->true_region); free (if_region->region); free (if_region); @@ -1502,7 +1514,7 @@ gloog (scop_p scop, htab_t bb_pbb_mapping) num_no_dependency); } - return true; + return !gloog_error; } #endif diff --git a/gcc/sese.c b/gcc/sese.c index 1c4686de3a2..f959bdb269e 100644 --- a/gcc/sese.c +++ b/gcc/sese.c @@ -1558,6 +1558,34 @@ move_sese_in_condition (sese region) return if_region; } +/* Replaces the condition of the IF_REGION with CONDITION: + | if (CONDITION) + | true_region; + | else + | false_region; +*/ + +void +set_ifsese_condition (ifsese if_region, tree condition) +{ + sese region = if_region->region; + edge entry = region->entry; + basic_block bb = entry->dest; + gimple last = last_stmt (bb); + gimple_stmt_iterator gsi = gsi_last_bb (bb); + gimple cond_stmt; + + gcc_assert (gimple_code (last) == GIMPLE_COND); + + gsi_remove (&gsi, true); + gsi = gsi_last_bb (bb); + condition = force_gimple_operand_gsi (&gsi, condition, true, NULL, + false, GSI_NEW_STMT); + cond_stmt = gimple_build_cond_from_tree (condition, NULL_TREE, NULL_TREE); + gsi = gsi_last_bb (bb); + gsi_insert_after (&gsi, cond_stmt, GSI_NEW_STMT); +} + /* Returns the scalar evolution of T in REGION. Every variable that is not defined in the REGION is considered a parameter. */ diff --git a/gcc/sese.h b/gcc/sese.h index 350ae48241e..a54854a7610 100644 --- a/gcc/sese.h +++ b/gcc/sese.h @@ -229,6 +229,7 @@ extern ifsese create_if_region_on_edge (edge, tree); extern ifsese move_sese_in_condition (sese); extern edge get_true_edge_from_guard_bb (basic_block); extern edge get_false_edge_from_guard_bb (basic_block); +extern void set_ifsese_condition (ifsese, tree); static inline edge if_region_entry (ifsese if_region) diff --git a/gcc/testsuite/g++.dg/graphite/pr42681.C b/gcc/testsuite/g++.dg/graphite/pr42681.C new file mode 100644 index 00000000000..4593e1be416 --- /dev/null +++ b/gcc/testsuite/g++.dg/graphite/pr42681.C @@ -0,0 +1,17 @@ +/* { dg-options "-O1 -fgraphite-identity -fno-loop-block -fno-loop-interchange -fno-loop-strip-mine" } */ + +typedef long unsigned int size_t; +inline void* operator new(size_t, void* __p) throw() { return __p; } + +struct A { + int i, j; + A() : i(0) {} +}; + +void Init(A *a) +{ + for (int i = 0; i < 20; i++) { + new (&a[i]) A; + a[i].j = 0; + } +} -- 2.11.4.GIT