From 834a2c295bbce223924e2788f281b8429d30b2f8 Mon Sep 17 00:00:00 2001 From: amker Date: Thu, 15 Sep 2016 16:31:35 +0000 Subject: PR tree-optimization/77503 * tree-vect-loop.c (vectorizable_reduction): Record reduction code for CONST_COND_REDUCTION at analysis stage and use it at transform stage. * tree-vectorizer.h (struct _stmt_vec_info): New field. (STMT_VINFO_VEC_CONST_COND_REDUC_CODE): New macro. * tree-vect-stmts.c (new_stmt_vec_info): Initialize above new field. gcc/testsuite * gcc.dg/vect/pr77503.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@240166 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/tree-vect-loop.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'gcc/tree-vect-loop.c') diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index fa06505d1f2..58f3456fe40 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -5438,7 +5438,7 @@ vectorizable_reduction (gimple *stmt, gimple_stmt_iterator *gsi, tree def0, def1, tem, op1 = NULL_TREE; bool first_p = true; tree cr_index_scalar_type = NULL_TREE, cr_index_vector_type = NULL_TREE; - tree cond_reduc_val = NULL_TREE, const_cond_cmp = NULL_TREE; + tree cond_reduc_val = NULL_TREE; /* In case of reduction chain we switch to the first stmt in the chain, but we don't update STMT_INFO, since only the last stmt is marked as reduction @@ -5645,7 +5645,19 @@ vectorizable_reduction (gimple *stmt, gimple_stmt_iterator *gsi, = INTEGER_INDUC_COND_REDUCTION; } - if (cond_reduc_dt == vect_constant_def) + /* Loop peeling modifies initial value of reduction PHI, which + makes the reduction stmt to be transformed different to the + original stmt analyzed. We need to record reduction code for + CONST_COND_REDUCTION type reduction at analyzing stage, thus + it can be used directly at transform stage. */ + if (STMT_VINFO_VEC_CONST_COND_REDUC_CODE (stmt_info) == MAX_EXPR + || STMT_VINFO_VEC_CONST_COND_REDUC_CODE (stmt_info) == MIN_EXPR) + { + /* Also set the reduction type to CONST_COND_REDUCTION. */ + gcc_assert (cond_reduc_dt == vect_constant_def); + STMT_VINFO_VEC_REDUCTION_TYPE (stmt_info) = CONST_COND_REDUCTION; + } + else if (cond_reduc_dt == vect_constant_def) { enum vect_def_type cond_initial_dt; gimple *def_stmt = SSA_NAME_DEF_STMT (ops[reduc_index]); @@ -5667,7 +5679,9 @@ vectorizable_reduction (gimple *stmt, gimple_stmt_iterator *gsi, dump_printf_loc (MSG_NOTE, vect_location, "condition expression based on " "compile time constant.\n"); - const_cond_cmp = e; + /* Record reduction code at analysis stage. */ + STMT_VINFO_VEC_CONST_COND_REDUC_CODE (stmt_info) + = integer_onep (e) ? MAX_EXPR : MIN_EXPR; STMT_VINFO_VEC_REDUCTION_TYPE (stmt_info) = CONST_COND_REDUCTION; } @@ -5821,10 +5835,8 @@ vectorizable_reduction (gimple *stmt, gimple_stmt_iterator *gsi, we want to base our reduction around. */ if (STMT_VINFO_VEC_REDUCTION_TYPE (stmt_info) == CONST_COND_REDUCTION) { - gcc_assert (const_cond_cmp != NULL_TREE); - gcc_assert (integer_onep (const_cond_cmp) - || integer_zerop (const_cond_cmp)); - orig_code = integer_onep (const_cond_cmp) ? MAX_EXPR : MIN_EXPR; + orig_code = STMT_VINFO_VEC_CONST_COND_REDUC_CODE (stmt_info); + gcc_assert (orig_code == MAX_EXPR || orig_code == MIN_EXPR); } else if (STMT_VINFO_VEC_REDUCTION_TYPE (stmt_info) == INTEGER_INDUC_COND_REDUCTION) -- cgit v1.2.1