From 89d390e57a34432f9a8f14b752eec061fcb2b64e Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 23 Mar 2015 12:47:54 +0000 Subject: [PATCH] re PR tree-optimization/65494 (Loop is not vectorized because of operand canonicalization.) 2015-03-23 Richard Biener PR tree-optimization/65494 * tree-vect-slp.c (vect_build_slp_tree): Do not (re-)allocate matches here. (vect_analyze_slp_instance): But do that here, always and once. * gcc.dg/vect/pr65494.c: New testcase. From-SVN: r221592 --- gcc/ChangeLog | 7 +++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/vect/pr65494.c | 28 ++++++++++++++++++++++++++++ gcc/tree-vect-slp.c | 12 ++++-------- 4 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr65494.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d269b76c464..cb657f66fa8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2015-03-23 Richard Biener + + PR tree-optimization/65494 + * tree-vect-slp.c (vect_build_slp_tree): Do not (re-)allocate + matches here. + (vect_analyze_slp_instance): But do that here, always and once. + 2015-03-23 Kyrylo Tkachov * expmed.c (synth_mult): Fix comment about multiplying by T-1 and diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9b84418bc81..cafb23b4b27 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-03-23 Richard Biener + + PR tree-optimization/65494 + * gcc.dg/vect/pr65494.c: New testcase. + 2015-03-23 Jakub Jelinek PR preprocessor/65238 diff --git a/gcc/testsuite/gcc.dg/vect/pr65494.c b/gcc/testsuite/gcc.dg/vect/pr65494.c new file mode 100644 index 00000000000..753985f7e50 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr65494.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-Ofast -funroll-loops" } */ + +typedef unsigned char uchar; +typedef struct rgb_ {uchar r; uchar g; uchar b;} rgb; +#define N 512 +rgb in[N], out[N]; +float c[N]; +void foo(int n) +{ + int i, j; + for (i = 0; i < n; i++) //in and out are RGB byte arrays + { + float r = 0, g = 0, b = 0; + for (j = 0; j < 5; j++) + { + r += (float)in[i + j].r * c[j]; + g += (float)in[i + j].g * c[j]; + b += (float)in[i + j].b * c[j]; + } + out[i].r = (uchar)r; + out[i].g = (uchar)g; + out[i].b = (uchar)b; + } +} + +/* { dg-final { scan-tree-dump "vectorized 1 loops in function" "vect" { target { vect_float && vect_intfloat_cvt } } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index ce0ca910302..c57a5caf68b 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -926,14 +926,9 @@ vect_build_slp_tree (loop_vec_info loop_vinfo, bb_vec_info bb_vinfo, bool *matches, unsigned *npermutes, unsigned *tree_size, unsigned max_tree_size) { - unsigned nops, i, this_npermutes = 0, this_tree_size = 0; + unsigned nops, i, this_tree_size = 0; gimple stmt; - if (!matches) - matches = XALLOCAVEC (bool, group_size); - if (!npermutes) - npermutes = &this_npermutes; - matches[0] = false; stmt = SLP_TREE_SCALAR_STMTS (*node)[0]; @@ -1012,7 +1007,6 @@ vect_build_slp_tree (loop_vec_info loop_vinfo, bb_vec_info bb_vinfo, return false; } - bool *matches = XALLOCAVEC (bool, group_size); if (vect_build_slp_tree (loop_vinfo, bb_vinfo, &child, group_size, max_nunits, loads, vectorization_factor, matches, @@ -1637,9 +1631,11 @@ vect_analyze_slp_instance (loop_vec_info loop_vinfo, bb_vec_info bb_vinfo, loads.create (group_size); /* Build the tree for the SLP instance. */ + bool *matches = XALLOCAVEC (bool, group_size); + unsigned npermutes = 0; if (vect_build_slp_tree (loop_vinfo, bb_vinfo, &node, group_size, &max_nunits, &loads, - vectorization_factor, NULL, NULL, NULL, + vectorization_factor, matches, &npermutes, NULL, max_tree_size)) { /* Calculate the unrolling factor based on the smallest type. */ -- 2.30.2