From ebc047a210e17c5facf31ff11eddaac9db4d4a95 Mon Sep 17 00:00:00 2001 From: Cong Hou Date: Fri, 4 Apr 2014 21:27:21 -0400 Subject: [PATCH] re PR tree-optimization/60656 (x86 vectorization produces wrong code) 2014-04-04 Cong Hou PR tree-optimization/60656 * tree-vect-stmts.c (supportable_widening_operation): Fix a bug that elements in a vector with vect_used_by_reduction property are incorrectly reordered when the operation on it is not consistant with the one in reduction operation. 2014-04-04 Cong Hou PR tree-optimization/60656 * gcc.dg/vect/pr60656.c: New test. From-SVN: r209138 --- gcc/ChangeLog | 8 +++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/vect/pr60656.c | 45 +++++++++++++++++++++++++++++ gcc/tree-vect-stmts.c | 16 +++++++++- 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr60656.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c6d836576da..b561dce0c92 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2014-04-04 Cong Hou + + PR tree-optimization/60656 + * tree-vect-stmts.c (supportable_widening_operation): + Fix a bug that elements in a vector with vect_used_by_reduction + property are incorrectly reordered when the operation on it is not + consistant with the one in reduction operation. + 2014-04-04 John David Anglin PR rtl-optimization/60155 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7d030fd64a8..a0af48c0502 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-04-04 Cong Hou + + PR tree-optimization/60656 + * gcc.dg/vect/pr60656.c: New test. + 2014-04-04 Andreas Krebbel * gcc.dg/builtin-bswap-6.c: Adjust return value to disable GCC diff --git a/gcc/testsuite/gcc.dg/vect/pr60656.c b/gcc/testsuite/gcc.dg/vect/pr60656.c new file mode 100644 index 00000000000..ebaab62b97c --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr60656.c @@ -0,0 +1,45 @@ +/* { dg-require-effective-target vect_int } */ + +#include "tree-vect.h" + +__attribute__ ((noinline)) long +foo () +{ + int v[] = {5000, 5001, 5002, 5003}; + long s = 0; + int i; + + for(i = 0; i < 4; ++i) + { + long P = v[i]; + s += P*P*P; + } + return s; +} + +long +bar () +{ + int v[] = {5000, 5001, 5002, 5003}; + long s = 0; + int i; + + for(i = 0; i < 4; ++i) + { + long P = v[i]; + s += P*P*P; + __asm__ volatile (""); + } + return s; +} + +int main() +{ + if (foo () != bar ()) + abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ + diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c index 884e769c884..1a51d6d7b57 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -7848,7 +7848,21 @@ supportable_widening_operation (enum tree_code code, gimple stmt, stmt, vectype_out, vectype_in, code1, code2, multi_step_cvt, interm_types)) - return true; + { + /* Elements in a vector with vect_used_by_reduction property cannot + be reordered if the use chain with this property does not have the + same operation. One such an example is s += a * b, where elements + in a and b cannot be reordered. Here we check if the vector defined + by STMT is only directly used in the reduction statement. */ + tree lhs = gimple_assign_lhs (stmt); + use_operand_p dummy; + gimple use_stmt; + stmt_vec_info use_stmt_info = NULL; + if (single_imm_use (lhs, &dummy, &use_stmt) + && (use_stmt_info = vinfo_for_stmt (use_stmt)) + && STMT_VINFO_DEF_TYPE (use_stmt_info) == vect_reduction_def) + return true; + } c1 = VEC_WIDEN_MULT_LO_EXPR; c2 = VEC_WIDEN_MULT_HI_EXPR; break; -- 2.30.2