We were blindly costing all scalar stmts that appear in patterns even if those are not relevant for vectorization. Fixed as follows.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2019-01-25 Richard Biener <rguent...@suse.de> PR tree-optimization/89049 * tree-vect-loop.c (vect_compute_single_scalar_iteration_cost): Look at the pattern stmt to determine if the stmt is vectorized. Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c (revision 268257) +++ gcc/tree-vect-loop.c (working copy) @@ -1100,11 +1100,11 @@ vect_compute_single_scalar_iteration_cos continue; /* Skip stmts that are not vectorized inside the loop. */ - if (stmt_info - && !STMT_VINFO_RELEVANT_P (stmt_info) - && (!STMT_VINFO_LIVE_P (stmt_info) - || !VECTORIZABLE_CYCLE_DEF (STMT_VINFO_DEF_TYPE (stmt_info))) - && !STMT_VINFO_IN_PATTERN_P (stmt_info)) + stmt_vec_info vstmt_info = vect_stmt_to_vectorize (stmt_info); + if (!STMT_VINFO_RELEVANT_P (vstmt_info) + && (!STMT_VINFO_LIVE_P (vstmt_info) + || !VECTORIZABLE_CYCLE_DEF + (STMT_VINFO_DEF_TYPE (vstmt_info)))) continue; vect_cost_for_stmt kind;