From 4f1f33aa8255271e5504ca6a0dcdea0f4f9b0b79 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 10 Dec 2007 23:49:43 +0100 Subject: [PATCH] re PR tree-optimization/34371 (verify_stmts failed (incorrect sharing of tree nodes)) PR tree-optimization/34371 * tree-vectorizer.h (struct _loop_vec_info): Add num_iters_unchanged field. (LOOP_VINFO_NITERS_UNCHANGED): Define to num_iters_unchanged field. * tree-vectorizer.c (set_prologue_iterations, slpeel_tree_peel_loop_to_edge): Call unshare_expr on LOOP_VINFO_NITERS_UNCHANGED before using it. * gcc.c-torture/compile/20071207-1.c: New test. From-SVN: r130755 --- gcc/ChangeLog | 10 ++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.c-torture/compile/20071207-1.c | 14 ++++++++++++++ gcc/tree-vectorizer.c | 11 ++++++----- gcc/tree-vectorizer.h | 3 ++- 5 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/20071207-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c57f46eac80..c2c01545aa9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2007-12-10 Jakub Jelinek + + PR tree-optimization/34371 + * tree-vectorizer.h (struct _loop_vec_info): Add num_iters_unchanged + field. + (LOOP_VINFO_NITERS_UNCHANGED): Define to num_iters_unchanged field. + * tree-vectorizer.c (set_prologue_iterations, + slpeel_tree_peel_loop_to_edge): Call unshare_expr on + LOOP_VINFO_NITERS_UNCHANGED before using it. + 2007-12-10 Eric Botcazou PR target/34403 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 099f0291e22..4774d300efc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-12-10 Jakub Jelinek + + PR tree-optimization/34371 + * gcc.c-torture/compile/20071207-1.c: New test. + 2007-12-10 Simon Martin PR c++/34059 diff --git a/gcc/testsuite/gcc.c-torture/compile/20071207-1.c b/gcc/testsuite/gcc.c-torture/compile/20071207-1.c new file mode 100644 index 00000000000..27b871616b1 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/20071207-1.c @@ -0,0 +1,14 @@ +/* PR tree-optimization/34371 */ +/* Testcase by Martin Michlmayr */ + +void centerln (int width, int ch, char *s) +{ + unsigned int sidebar; + int i; + char linet1[1000]; + char linet2[100]; + sidebar = (width - __builtin_strlen (s)) / 2; + for (i = 0; i < sidebar; i++) + linet2[i] = ch; + __builtin_strcpy (linet1, linet2); +} diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c index fcc74168c46..0131b9a4aaf 100644 --- a/gcc/tree-vectorizer.c +++ b/gcc/tree-vectorizer.c @@ -1037,7 +1037,7 @@ set_prologue_iterations (basic_block bb_before_first_loop, tree gimplify_stmt_list; tree cost_pre_condition = NULL_TREE; tree scalar_loop_iters = - LOOP_VINFO_NITERS_UNCHANGED (loop_vec_info_for_loop (loop)); + unshare_expr (LOOP_VINFO_NITERS_UNCHANGED (loop_vec_info_for_loop (loop))); e = single_pred_edge (bb_before_first_loop); cond_bb = split_edge(e); @@ -1154,8 +1154,6 @@ slpeel_tree_peel_loop_to_edge (struct loop *loop, edge exit_e = single_exit (loop); LOC loop_loc; tree cost_pre_condition = NULL_TREE; - tree scalar_loop_iters = - LOOP_VINFO_NITERS_UNCHANGED (loop_vec_info_for_loop (loop)); if (!slpeel_can_duplicate_loop_p (loop, e)) return NULL; @@ -1307,10 +1305,13 @@ slpeel_tree_peel_loop_to_edge (struct loop *loop, build_int_cst (TREE_TYPE (first_niters), 0)); if (check_profitability) { - cost_pre_condition = + tree scalar_loop_iters + = unshare_expr (LOOP_VINFO_NITERS_UNCHANGED + (loop_vec_info_for_loop (loop))); + cost_pre_condition = build2 (LE_EXPR, boolean_type_node, scalar_loop_iters, build_int_cst (TREE_TYPE (scalar_loop_iters), th)); - + pre_condition = fold_build2 (TRUTH_OR_EXPR, boolean_type_node, cost_pre_condition, pre_condition); } diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h index d7d447652e9..0f3c34ef62a 100644 --- a/gcc/tree-vectorizer.h +++ b/gcc/tree-vectorizer.h @@ -164,6 +164,7 @@ typedef struct _loop_vec_info { /* Number of iterations. */ tree num_iters; + tree num_iters_unchanged; /* Minimum number of iterations below which vectorization is expected to not be profitable (as estimated by the cost model). @@ -230,7 +231,7 @@ typedef struct _loop_vec_info { #define LOOP_VINFO_NITERS(L) (L)->num_iters /* Since LOOP_VINFO_NITERS can change after prologue peeling retain total unchanged scalar loop iterations for cost model. */ -#define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters +#define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L) (L)->min_profitable_iters #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor -- 2.30.2