From: Richard Biener Date: Wed, 31 Jul 2019 14:15:37 +0000 (+0000) Subject: re PR tree-optimization/91293 (Wrong code with -O3 -mavx2) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2153fa7b60a430970cfebade3b04c6a4dd3e83f6;p=gcc.git re PR tree-optimization/91293 (Wrong code with -O3 -mavx2) 2019-07-31 Richard Biener PR tree-optimization/91293 * tree-vect-slp.c (vect_build_slp_tree_2): Do not swap operands of reduction stmts. * gcc.dg/vect/pr91293-1.c: New testcase. * gcc.dg/vect/pr91293-2.c: Likewise. * gcc.dg/vect/pr91293-3.c: Likewise. From-SVN: r273934 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 812465757c0..ef8ee9fc2a5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-07-31 Richard Biener + + PR tree-optimization/91293 + * tree-vect-slp.c (vect_build_slp_tree_2): Do not swap operands + of reduction stmts. + 2019-07-31 Matt Thomas Nick Hudson Matthew Green diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 91378f2cff6..6cffdc28da9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-07-31 Richard Biener + + PR tree-optimization/91293 + * gcc.dg/vect/pr91293-1.c: New testcase. + * gcc.dg/vect/pr91293-2.c: Likewise. + * gcc.dg/vect/pr91293-3.c: Likewise. + 2019-07-31 Jakub Jelinek PR tree-optimization/91201 diff --git a/gcc/testsuite/gcc.dg/vect/pr91293-1.c b/gcc/testsuite/gcc.dg/vect/pr91293-1.c new file mode 100644 index 00000000000..dc321f5726f --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr91293-1.c @@ -0,0 +1,19 @@ +/* { dg-do run } */ +/* { dg-additional-options "-msse4.1" { target { sse4_runtime } } } */ + +long long a; +unsigned b, c; +int d = 62; +void e(long long *f, int p2) { *f = p2; } +int main() +{ + for (int g = 2; g <= d; g++) + { + b += g + 4; + c += 5 - g; + } + e(&a, b); + if (a != 2196) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/vect/pr91293-2.c b/gcc/testsuite/gcc.dg/vect/pr91293-2.c new file mode 100644 index 00000000000..b9354bbd5e8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr91293-2.c @@ -0,0 +1,19 @@ +/* { dg-do run } */ +/* { dg-additional-options "-msse4.1" { target { sse4_runtime } } } */ + +long long a; +unsigned b, c; +int d = 62; +void e(long long *f, int p2) { *f = p2; } +int main() +{ + for (int g = 2; g <= d; g++) + { + c += 5 - g; + b += g + 4; + } + e(&a, b); + if (a != 2196) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/vect/pr91293-3.c b/gcc/testsuite/gcc.dg/vect/pr91293-3.c new file mode 100644 index 00000000000..c35bc3481cb --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr91293-3.c @@ -0,0 +1,20 @@ +/* { dg-do run } */ +/* { dg-additional-options "-msse4.1" { target { sse4_runtime } } } */ + +long long a; +unsigned b, c; +int d = 62; +void e(long long *f, int p2) { *f = p2; } +int xx = 5, yy = 4; +int main() +{ + for (int g = 2; g <= d; g++) + { + c += xx - g; + b += yy + g; + } + e(&a, b); + if (a != 2196) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index 0220b1804fb..52f2a06e3b8 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -1296,6 +1296,9 @@ vect_build_slp_tree_2 (vec_info *vinfo, && nops == 2 && oprnds_info[1]->first_dt == vect_internal_def && is_gimple_assign (stmt_info->stmt) + /* Swapping operands for reductions breaks assumptions later on. */ + && STMT_VINFO_DEF_TYPE (stmt_info) != vect_reduction_def + && STMT_VINFO_DEF_TYPE (stmt_info) != vect_double_reduction_def /* Do so only if the number of not successful permutes was nor more than a cut-ff as re-trying the recursive match on possibly each level of the tree would expose exponential