From c449d3ae28ff4e133114fb67dbf7dcc7a95ca5d5 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Thu, 19 Sep 2019 13:33:55 +0000 Subject: Enforce correct COND_EXPR order for EXTRACT_LAST_REDUCTION For conditional reductions, the "then" value needs to be the candidate value calculated by this iteration while the "else" value needs to be the result carried over from previous iterations. If the COND_EXPR is the other way around, we need to swap it. 2019-09-19 Richard Sandiford gcc/ * tree-vectorizer.h (vectorizable_condition): Take an int reduction index instead of a boolean flag. * tree-vect-stmts.c (vectorizable_condition): Likewise. Swap the "then" and "else" values for EXTRACT_LAST_REDUCTION reductions if the reduction accumulator is the "then" rather than the "else" value. (vect_analyze_stmt): Update call accordingly. (vect_transform_stmt): Likewise. * tree-vect-loop.c (vectorizable_reduction): Likewise, asserting that the index is > 0. From-SVN: r275962 --- gcc/tree-vect-loop.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'gcc/tree-vect-loop.c') diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index 5ee4ee3..aec4462 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -6659,8 +6659,9 @@ vectorizable_reduction (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, { /* Only call during the analysis stage, otherwise we'll lose STMT_VINFO_TYPE. */ + gcc_assert (reduc_index > 0); if (!vec_stmt && !vectorizable_condition (stmt_info, gsi, NULL, - true, NULL, cost_vec)) + reduc_index, NULL, cost_vec)) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, @@ -7113,9 +7114,9 @@ vectorizable_reduction (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, if (reduction_type == EXTRACT_LAST_REDUCTION) { - gcc_assert (!slp_node); + gcc_assert (!slp_node && reduc_index > 0); return vectorizable_condition (stmt_info, gsi, vec_stmt, - true, NULL, NULL); + reduc_index, NULL, NULL); } /* Create the destination vector */ @@ -7145,9 +7146,9 @@ vectorizable_reduction (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, { if (code == COND_EXPR) { - gcc_assert (!slp_node); + gcc_assert (!slp_node && reduc_index > 0); vectorizable_condition (stmt_info, gsi, vec_stmt, - true, NULL, NULL); + reduc_index, NULL, NULL); break; } if (code == LSHIFT_EXPR -- cgit v1.1