aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCong Hou <congh@google.com>2014-04-04 21:27:21 -0400
committerCong Hou <congh@gcc.gnu.org>2014-04-04 21:27:21 -0400
commitebc047a210e17c5facf31ff11eddaac9db4d4a95 (patch)
treed1e18f32f3b8c5ae7bca649f5c026af77d3cd5ed
parent604fb578094200cc3771cc84c267cffa2fc47a6d (diff)
downloadgcc-ebc047a210e17c5facf31ff11eddaac9db4d4a95.zip
gcc-ebc047a210e17c5facf31ff11eddaac9db4d4a95.tar.gz
gcc-ebc047a210e17c5facf31ff11eddaac9db4d4a95.tar.bz2
re PR tree-optimization/60656 (x86 vectorization produces wrong code)
2014-04-04 Cong Hou <congh@google.com> 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 <congh@google.com> PR tree-optimization/60656 * gcc.dg/vect/pr60656.c: New test. From-SVN: r209138
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/vect/pr60656.c45
-rw-r--r--gcc/tree-vect-stmts.c16
4 files changed, 73 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c6d8365..b561dce 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2014-04-04 Cong Hou <congh@google.com>
+
+ 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 <danglin@gcc.gnu.org>
PR rtl-optimization/60155
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7d030fd..a0af48c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-04-04 Cong Hou <congh@google.com>
+
+ PR tree-optimization/60656
+ * gcc.dg/vect/pr60656.c: New test.
+
2014-04-04 Andreas Krebbel <Andreas.Krebbel@de.ibm.com>
* 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 0000000..ebaab62
--- /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 884e769..1a51d6d 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;