+2016-09-15 Bin Cheng <bin.cheng@arm.com>
+
+ 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.
+
2016-09-15 Richard Biener <rguenther@suse.de>
PR middle-end/77544
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
= 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]);
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;
}
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)
/* For reduction loops, this is the type of reduction. */
enum vect_reduction_type v_reduc_type;
+ /* For CONST_COND_REDUCTION, record the reduc code. */
+ enum tree_code const_cond_reduc_code;
+
/* The number of scalar stmt references from active SLP instances. */
unsigned int num_slp_uses;
} *stmt_vec_info;
#define STMT_VINFO_MEMORY_ACCESS_TYPE(S) (S)->memory_access_type
#define STMT_VINFO_SIMD_LANE_ACCESS_P(S) (S)->simd_lane_access_p
#define STMT_VINFO_VEC_REDUCTION_TYPE(S) (S)->v_reduc_type
+#define STMT_VINFO_VEC_CONST_COND_REDUC_CODE(S) (S)->const_cond_reduc_code
#define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address
#define STMT_VINFO_DR_INIT(S) (S)->dr_init