From: Richard Biener Date: Fri, 25 Mar 2022 13:31:25 +0000 (+0100) Subject: tree-optimization/105053 - fix reduction chain epilogue generation X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fe705dce2e1e3e4e5e0c69d7f9adaf7f2777cdc8;p=test_jj.git tree-optimization/105053 - fix reduction chain epilogue generation When we optimize permutations in a reduction chain we have to be careful to select the correct live-out stmt, otherwise the reduction result will be unused and the retained scalar code will execute only the number of vector iterations. 2022-03-25 Richard Biener PR tree-optimization/105053 * tree-vect-loop.cc (vect_create_epilog_for_reduction): Pick the correct live-out stmt for a reduction chain. * g++.dg/vect/pr105053.cc: New testcase. --- diff --git a/gcc/testsuite/g++.dg/vect/pr105053.cc b/gcc/testsuite/g++.dg/vect/pr105053.cc new file mode 100644 index 0000000..6deef84 --- /dev/null +++ b/gcc/testsuite/g++.dg/vect/pr105053.cc @@ -0,0 +1,25 @@ +// { dg-require-effective-target c++11 } +// { dg-require-effective-target int32plus } + +#include +#include +#include + +int main() +{ + const int n = 4; + std::vector> vec + = { { 1597201307, 1817606674, 0. }, + { 1380347796, 1721941769, 0.}, + {837975613, 1032707773, 0.}, + {1173654292, 2020064272, 0.} } ; + int sup1 = 0; + for(int i=0;i(vec[i]),std::get<1>(vec[i]))); + int sup2 = 0; + for(int i=0;i(vec[i])),std::get<1>(vec[i])); + if (sup1 != sup2) + std::abort (); + return 0; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 7a74633..d7bc346 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -5271,9 +5271,17 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo, /* All statements produce live-out values. */ live_out_stmts = SLP_TREE_SCALAR_STMTS (slp_node); else if (slp_node) - /* The last statement in the reduction chain produces the live-out - value. */ - single_live_out_stmt[0] = SLP_TREE_SCALAR_STMTS (slp_node)[group_size - 1]; + { + /* The last statement in the reduction chain produces the live-out + value. Note SLP optimization can shuffle scalar stmts to + optimize permutations so we have to search for the last stmt. */ + for (k = 0; k < group_size; ++k) + if (!REDUC_GROUP_NEXT_ELEMENT (SLP_TREE_SCALAR_STMTS (slp_node)[k])) + { + single_live_out_stmt[0] = SLP_TREE_SCALAR_STMTS (slp_node)[k]; + break; + } + } unsigned vec_num; int ncopies;