aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vect-loop.cc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2024-09-18 12:41:25 +0200
committerRichard Biener <rguenth@gcc.gnu.org>2024-09-19 16:26:28 +0200
commit77bd23a3e247555ba427d01af8e5713934be8d5b (patch)
treee6c1df8f2e40f68e6687b583fb60ade8f4b1c4bb /gcc/tree-vect-loop.cc
parentd3a7302ec5985abcda561886cc724d388c7143cb (diff)
downloadgcc-77bd23a3e247555ba427d01af8e5713934be8d5b.zip
gcc-77bd23a3e247555ba427d01af8e5713934be8d5b.tar.gz
gcc-77bd23a3e247555ba427d01af8e5713934be8d5b.tar.bz2
Fall back to single-lane SLP before falling back to no SLP
The following changes the fallback to disable SLP when any of the discovered SLP instances failed to pass vectorization checking into a fallback that emulates what no SLP would do with SLP - force single-lane discovery for all instances. The patch does not remove the final fallback to disable SLP but it reduces the fallout from failing vectorization when any non-SLP stmt survives analysis. * tree-vectorizer.h (vect_analyze_slp): Add force_single_lane parameter. * tree-vect-slp.cc (vect_analyze_slp_instance): Remove defaulting of force_single_lane. (vect_build_slp_instance): Likewise. Pass down appropriate force_single_lane. (vect_analyze_slp): Add force_sigle_lane parameter and pass it down appropriately. (vect_slp_analyze_bb_1): Always do multi-lane SLP. * tree-vect-loop.cc (vect_analyze_loop_2): Track two SLP modes and adjust accordingly. (vect_analyze_loop_1): Save the SLP mode when unrolling. * gcc.dg/vect/vect-outer-slp-1.c: Adjust.
Diffstat (limited to 'gcc/tree-vect-loop.cc')
-rw-r--r--gcc/tree-vect-loop.cc49
1 files changed, 27 insertions, 22 deletions
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index c6778ab..0f54ebe 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -2718,7 +2718,7 @@ vect_determine_partial_vectors_and_peeling (loop_vec_info loop_vinfo)
static opt_result
vect_analyze_loop_2 (loop_vec_info loop_vinfo, bool &fatal,
unsigned *suggested_unroll_factor,
- bool& slp_done_for_suggested_uf)
+ unsigned& slp_done_for_suggested_uf)
{
opt_result ok = opt_result::success ();
int res;
@@ -2787,11 +2787,11 @@ vect_analyze_loop_2 (loop_vec_info loop_vinfo, bool &fatal,
/* If the slp decision is false when suggested unroll factor is worked
out, and we are applying suggested unroll factor, we can simply skip
all slp related analyses this time. */
- bool slp = !applying_suggested_uf || slp_done_for_suggested_uf;
+ unsigned slp = !applying_suggested_uf ? 2 : slp_done_for_suggested_uf;
/* Classify all cross-iteration scalar data-flow cycles.
Cross-iteration cycles caused by virtual phis are analyzed separately. */
- vect_analyze_scalar_cycles (loop_vinfo, slp);
+ vect_analyze_scalar_cycles (loop_vinfo, slp == 2);
vect_pattern_recog (loop_vinfo);
@@ -2854,18 +2854,23 @@ vect_analyze_loop_2 (loop_vec_info loop_vinfo, bool &fatal,
vect_compute_single_scalar_iteration_cost (loop_vinfo);
poly_uint64 saved_vectorization_factor = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
+ bool saved_can_use_partial_vectors_p
+ = LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo);
+
+ /* This is the point where we can re-start analysis with SLP forced off. */
+start_over:
if (slp)
{
/* Check the SLP opportunities in the loop, analyze and build
SLP trees. */
- ok = vect_analyze_slp (loop_vinfo, LOOP_VINFO_N_STMTS (loop_vinfo));
+ ok = vect_analyze_slp (loop_vinfo, LOOP_VINFO_N_STMTS (loop_vinfo),
+ slp == 1);
if (!ok)
return ok;
/* If there are any SLP instances mark them as pure_slp. */
- slp = vect_make_slp_decision (loop_vinfo);
- if (slp)
+ if (vect_make_slp_decision (loop_vinfo))
{
/* Find stmts that need to be both vectorized and SLPed. */
vect_detect_hybrid_slp (loop_vinfo);
@@ -2881,16 +2886,10 @@ vect_analyze_loop_2 (loop_vec_info loop_vinfo, bool &fatal,
}
}
- bool saved_can_use_partial_vectors_p
- = LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo);
-
/* We don't expect to have to roll back to anything other than an empty
set of rgroups. */
gcc_assert (LOOP_VINFO_MASKS (loop_vinfo).is_empty ());
- /* This is the point where we can re-start analysis with SLP forced off. */
-start_over:
-
/* When we arrive here with SLP disabled and we are supposed
to use SLP for everything fail vectorization. */
if (!slp && param_vect_force_slp)
@@ -3218,15 +3217,14 @@ again:
/* Ensure that "ok" is false (with an opt_problem if dumping is enabled). */
gcc_assert (!ok);
- /* Try again with SLP forced off but if we didn't do any SLP there is
+ /* Try again with SLP degraded but if we didn't do any SLP there is
no point in re-trying. */
if (!slp)
return ok;
- /* If the slp decision is true when suggested unroll factor is worked
- out, and we are applying suggested unroll factor, we don't need to
- re-try any more. */
- if (applying_suggested_uf && slp_done_for_suggested_uf)
+ /* If we are applying suggested unroll factor, we don't need to
+ re-try any more as we want to keep the SLP mode fixed. */
+ if (applying_suggested_uf)
return ok;
/* If there are reduction chains re-trying will fail anyway. */
@@ -3271,11 +3269,18 @@ again:
}
if (dump_enabled_p ())
- dump_printf_loc (MSG_NOTE, vect_location,
- "re-trying with SLP disabled\n");
+ {
+ if (slp)
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "re-trying with single-lane SLP\n");
+ else
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "re-trying with SLP disabled\n");
+ }
- /* Roll back state appropriately. No SLP this time. */
- slp = false;
+ /* Roll back state appropriately. Degrade SLP this time. From multi-
+ to single-lane to disabled. */
+ --slp;
/* Restore vectorization factor as it were without SLP. */
LOOP_VINFO_VECT_FACTOR (loop_vinfo) = saved_vectorization_factor;
/* Free the SLP instances. */
@@ -3420,7 +3425,7 @@ vect_analyze_loop_1 (class loop *loop, vec_info_shared *shared,
machine_mode vector_mode = vector_modes[mode_i];
loop_vinfo->vector_mode = vector_mode;
unsigned int suggested_unroll_factor = 1;
- bool slp_done_for_suggested_uf = false;
+ unsigned slp_done_for_suggested_uf = 0;
/* Run the main analysis. */
opt_result res = vect_analyze_loop_2 (loop_vinfo, fatal,