From 15f128a7193fe0724c9e1e4f0d6a015af7f1b97d Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 12 Oct 2015 08:33:34 +0000 Subject: [PATCH] tree-vect-loop.c (vect_analyze_loop_operations): Move cost related code ... 2015-10-12 Richard Biener * tree-vect-loop.c (vect_analyze_loop_operations): Move cost related code ... (vect_analyze_loop_2): ... here. From-SVN: r228705 --- gcc/ChangeLog | 6 ++ gcc/tree-vect-loop.c | 193 +++++++++++++++++++++---------------------- 2 files changed, 101 insertions(+), 98 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1ce0fbb896a..f46b4a64adb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-10-12 Richard Biener + + * tree-vect-loop.c (vect_analyze_loop_operations): Move cost + related code ... + (vect_analyze_loop_2): ... here. + 2015-10-11 Jason Merrill PR c++/67557 diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index 8ab1cdf3ac7..6b372389d6b 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -1430,17 +1430,10 @@ vect_analyze_loop_operations (loop_vec_info loop_vinfo) struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo); basic_block *bbs = LOOP_VINFO_BBS (loop_vinfo); int nbbs = loop->num_nodes; - unsigned int vectorization_factor; int i; stmt_vec_info stmt_info; bool need_to_vectorize = false; - int min_profitable_iters; - int min_scalar_loop_bound; - unsigned int th; bool ok; - HOST_WIDE_INT max_niter; - HOST_WIDE_INT estimated_niter; - int min_profitable_estimate; if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, @@ -1585,94 +1578,6 @@ vect_analyze_loop_operations (loop_vec_info loop_vinfo) return false; } - vectorization_factor = LOOP_VINFO_VECT_FACTOR (loop_vinfo); - gcc_assert (vectorization_factor != 0); - - if (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) && dump_enabled_p ()) - dump_printf_loc (MSG_NOTE, vect_location, - "vectorization_factor = %d, niters = " - HOST_WIDE_INT_PRINT_DEC "\n", vectorization_factor, - LOOP_VINFO_INT_NITERS (loop_vinfo)); - - if ((LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) - && (LOOP_VINFO_INT_NITERS (loop_vinfo) < vectorization_factor)) - || ((max_niter = max_stmt_executions_int (loop)) != -1 - && (unsigned HOST_WIDE_INT) max_niter < vectorization_factor)) - { - if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "not vectorized: iteration count too small.\n"); - if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "not vectorized: iteration count smaller than " - "vectorization factor.\n"); - return false; - } - - /* Analyze cost. Decide if worth while to vectorize. */ - - vect_estimate_min_profitable_iters (loop_vinfo, &min_profitable_iters, - &min_profitable_estimate); - LOOP_VINFO_COST_MODEL_MIN_ITERS (loop_vinfo) = min_profitable_iters; - - if (min_profitable_iters < 0) - { - if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "not vectorized: vectorization not profitable.\n"); - if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "not vectorized: vector version will never be " - "profitable.\n"); - return false; - } - - min_scalar_loop_bound = ((PARAM_VALUE (PARAM_MIN_VECT_LOOP_BOUND) - * vectorization_factor) - 1); - - - /* Use the cost model only if it is more conservative than user specified - threshold. */ - - th = (unsigned) min_scalar_loop_bound; - if (min_profitable_iters - && (!min_scalar_loop_bound - || min_profitable_iters > min_scalar_loop_bound)) - th = (unsigned) min_profitable_iters; - - LOOP_VINFO_COST_MODEL_THRESHOLD (loop_vinfo) = th; - - if (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) - && LOOP_VINFO_INT_NITERS (loop_vinfo) <= th) - { - if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "not vectorized: vectorization not profitable.\n"); - if (dump_enabled_p ()) - dump_printf_loc (MSG_NOTE, vect_location, - "not vectorized: iteration count smaller than user " - "specified loop bound parameter or minimum profitable " - "iterations (whichever is more conservative).\n"); - return false; - } - - if ((estimated_niter = estimated_stmt_executions_int (loop)) != -1 - && ((unsigned HOST_WIDE_INT) estimated_niter - <= MAX (th, (unsigned)min_profitable_estimate))) - { - if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "not vectorized: estimated iteration count too " - "small.\n"); - if (dump_enabled_p ()) - dump_printf_loc (MSG_NOTE, vect_location, - "not vectorized: estimated iteration count smaller " - "than specified loop bound parameter or minimum " - "profitable iterations (whichever is more " - "conservative).\n"); - return false; - } - return true; } @@ -1688,7 +1593,6 @@ vect_analyze_loop_2 (loop_vec_info loop_vinfo) bool ok; int max_vf = MAX_VECTORIZATION_FACTOR; int min_vf = 2; - unsigned int th; unsigned int n_stmts = 0; /* Find all data references in the loop (which correspond to vdefs/vuses) @@ -1786,6 +1690,33 @@ vect_analyze_loop_2 (loop_vec_info loop_vinfo) vect_update_vf_for_slp (loop_vinfo); } + /* Now the vectorization factor is final. */ + unsigned vectorization_factor = LOOP_VINFO_VECT_FACTOR (loop_vinfo); + gcc_assert (vectorization_factor != 0); + + if (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) && dump_enabled_p ()) + dump_printf_loc (MSG_NOTE, vect_location, + "vectorization_factor = %d, niters = " + HOST_WIDE_INT_PRINT_DEC "\n", vectorization_factor, + LOOP_VINFO_INT_NITERS (loop_vinfo)); + + HOST_WIDE_INT max_niter + = max_stmt_executions_int (LOOP_VINFO_LOOP (loop_vinfo)); + if ((LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) + && (LOOP_VINFO_INT_NITERS (loop_vinfo) < vectorization_factor)) + || (max_niter != -1 + && (unsigned HOST_WIDE_INT) max_niter < vectorization_factor)) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "not vectorized: iteration count too small.\n"); + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "not vectorized: iteration count smaller than " + "vectorization factor.\n"); + return false; + } + /* Analyze the alignment of the data-refs in the loop. Fail if a data reference is found that cannot be vectorized. */ @@ -1851,6 +1782,70 @@ vect_analyze_loop_2 (loop_vec_info loop_vinfo) return false; } + /* Analyze cost. Decide if worth while to vectorize. */ + int min_profitable_estimate, min_profitable_iters; + vect_estimate_min_profitable_iters (loop_vinfo, &min_profitable_iters, + &min_profitable_estimate); + LOOP_VINFO_COST_MODEL_MIN_ITERS (loop_vinfo) = min_profitable_iters; + + if (min_profitable_iters < 0) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "not vectorized: vectorization not profitable.\n"); + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "not vectorized: vector version will never be " + "profitable.\n"); + return false; + } + + int min_scalar_loop_bound = ((PARAM_VALUE (PARAM_MIN_VECT_LOOP_BOUND) + * vectorization_factor) - 1); + + /* Use the cost model only if it is more conservative than user specified + threshold. */ + unsigned th = (unsigned) min_scalar_loop_bound; + if (min_profitable_iters + && (!min_scalar_loop_bound + || min_profitable_iters > min_scalar_loop_bound)) + th = (unsigned) min_profitable_iters; + + LOOP_VINFO_COST_MODEL_THRESHOLD (loop_vinfo) = th; + + if (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) + && LOOP_VINFO_INT_NITERS (loop_vinfo) <= th) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "not vectorized: vectorization not profitable.\n"); + if (dump_enabled_p ()) + dump_printf_loc (MSG_NOTE, vect_location, + "not vectorized: iteration count smaller than user " + "specified loop bound parameter or minimum profitable " + "iterations (whichever is more conservative).\n"); + return false; + } + + HOST_WIDE_INT estimated_niter + = estimated_stmt_executions_int (LOOP_VINFO_LOOP (loop_vinfo)); + if (estimated_niter != -1 + && ((unsigned HOST_WIDE_INT) estimated_niter + <= MAX (th, (unsigned)min_profitable_estimate))) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "not vectorized: estimated iteration count too " + "small.\n"); + if (dump_enabled_p ()) + dump_printf_loc (MSG_NOTE, vect_location, + "not vectorized: estimated iteration count smaller " + "than specified loop bound parameter or minimum " + "profitable iterations (whichever is more " + "conservative).\n"); + return false; + } + /* Decide whether we need to create an epilogue loop to handle remaining scalar iterations. */ th = ((LOOP_VINFO_COST_MODEL_THRESHOLD (loop_vinfo) + 1) @@ -1873,8 +1868,7 @@ vect_analyze_loop_2 (loop_vec_info loop_vinfo) the epilogue is unnecessary. */ && ((!LOOP_REQUIRES_VERSIONING_FOR_ALIAS (loop_vinfo) && !LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT (loop_vinfo)) - || (unsigned HOST_WIDE_INT)max_stmt_executions_int - (LOOP_VINFO_LOOP (loop_vinfo)) > th))) + || (unsigned HOST_WIDE_INT) max_niter > th))) LOOP_VINFO_PEELING_FOR_NITER (loop_vinfo) = true; /* If an epilogue loop is required make sure we can create one. */ @@ -1896,6 +1890,9 @@ vect_analyze_loop_2 (loop_vec_info loop_vinfo) } } + gcc_assert (vectorization_factor + == (unsigned)LOOP_VINFO_VECT_FACTOR (loop_vinfo)); + return true; } -- 2.30.2