diff -Nurp a/gcc/common.opt b/gcc/common.opt --- a/gcc/common.opt 2020-06-20 23:53:56.124000000 +0800 +++ b/gcc/common.opt 2020-06-22 23:02:18.808000000 +0800 @@ -2858,6 +2858,10 @@ ftree-slp-vectorize Common Report Var(flag_tree_slp_vectorize) Optimization EnabledBy(ftree-vectorize) Enable basic block vectorization (SLP) on trees. +ftree-vect-analyze-slp-group +Common Report Var(flag_tree_slp_group) Init(0) +Disable SLP vectorization for reduction chain on tree. + fvect-cost-model= Common Joined RejectNegative Enum(vect_cost_model) Var(flag_vect_cost_model) Init(VECT_COST_MODEL_DEFAULT) Optimization -fvect-cost-model=[unlimited|dynamic|cheap] Specifies the cost model for vectorization. diff -Nurp a/gcc/testsuite/gcc.dg/vect/vect-reduc-12.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-12.c --- a/gcc/testsuite/gcc.dg/vect/vect-reduc-12.c 1970-01-01 08:00:00.000000000 +0800 +++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-12.c 2020-06-22 23:04:08.260000000 +0800 @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-vectorize -fdump-tree-vect-details -funsafe-math-optimizations -fno-tree-reassoc -ftree-vect-analyze-slp-group" } */ +void f(double *a, double *res, double m) { + double res1, res0; + res1 = 0; + res0 = 0; + for (int i = 0; i < 1000; i+=8) { + res0 += a[i] * m; + res1 += a[i+1] * m; + res0 += a[i+2] * m; + res1 += a[i+3] * m; + res0 += a[i+4] * m; + res1 += a[i+5] * m; + res0 += a[i+6] * m; + res1 += a[i+7] * m; + } + res[0] += res0; + res[1] += res1; +} +/* { dg-final { scan-tree-dump "vectorized 1 loops" "vect" } } */ diff -Nurp a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c --- a/gcc/tree-vect-slp.c 2020-06-21 01:07:56.516000000 +0800 +++ b/gcc/tree-vect-slp.c 2020-06-22 23:02:54.540000000 +0800 @@ -2327,8 +2327,9 @@ vect_analyze_slp (vec_info *vinfo, unsig { /* Find SLP sequences starting from reduction chains. */ FOR_EACH_VEC_ELT (loop_vinfo->reduction_chains, i, first_element) - if (! vect_analyze_slp_instance (vinfo, bst_map, first_element, + if (flag_tree_slp_group + || ! vect_analyze_slp_instance (vinfo, bst_map, first_element, max_tree_size)) { /* Dissolve reduction chain group. */ stmt_vec_info vinfo = first_element;