re PR tree-optimization/91293 (Wrong code with -O3 -mavx2)
authorRichard Biener <rguenther@suse.de>
Wed, 31 Jul 2019 14:15:37 +0000 (14:15 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 31 Jul 2019 14:15:37 +0000 (14:15 +0000)
2019-07-31  Richard Biener  <rguenther@suse.de>

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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/pr91293-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr91293-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr91293-3.c [new file with mode: 0644]
gcc/tree-vect-slp.c

index 812465757c0de2bf3d8feda0adbdfe5d4e3fe477..ef8ee9fc2a57ff4617b0d4160ab348c546f2b2a8 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-31  Richard Biener  <rguenther@suse.de>
+
+       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  <matt@3am-software.com>
            Nick Hudson <nick@nthcliff.demon.co.uk>
            Matthew Green <mrg@eterna.com.au>
index 91378f2cff60a8ab0d0fb57ae9867159fb56b50b..6cffdc28da99ab4db7df56829cb48feb4d740a13 100644 (file)
@@ -1,3 +1,10 @@
+2019-07-31  Richard Biener  <rguenther@suse.de>
+
+       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  <jakub@redhat.com>
 
        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 (file)
index 0000000..dc321f5
--- /dev/null
@@ -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 (file)
index 0000000..b9354bb
--- /dev/null
@@ -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 (file)
index 0000000..c35bc34
--- /dev/null
@@ -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;
+}
index 0220b1804fb1b00dae7df622d8bf45abb138b1a1..52f2a06e3b824e5aec1530b3b008e0681766396e 100644 (file)
@@ -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