]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/108782 - nested first order recurrence vectorization
authorRichard Biener <rguenther@suse.de>
Tue, 14 Feb 2023 10:10:56 +0000 (11:10 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 14 Feb 2023 11:49:42 +0000 (12:49 +0100)
First order recurrence vectorization isn't possible for nested
loops.

PR tree-optimization/108782
* tree-vect-loop.cc (vect_phi_first_order_recurrence_p):
Make sure we're not vectorizing an inner loop.

* gcc.dg/torture/pr108782.c: New testcase.

gcc/testsuite/gcc.dg/torture/pr108782.c [new file with mode: 0644]
gcc/tree-vect-loop.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr108782.c b/gcc/testsuite/gcc.dg/torture/pr108782.c
new file mode 100644 (file)
index 0000000..1eac93d
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fno-tree-copy-prop" } */
+
+int m;
+
+__attribute__ ((simd)) int
+foo (void)
+{
+  unsigned a;
+  int b = 0;
+
+  m = a = 1;
+  while (a != 0)
+    {
+      b = m;
+      m = 2;
+      ++a;
+    }
+
+  return b;
+}
index becf96bb2b804529a5f68cc1a759b279dce8c76f..8387f7690b2162d3d1c1519c71483537d5438da9 100644 (file)
@@ -538,6 +538,10 @@ static bool
 vect_phi_first_order_recurrence_p (loop_vec_info loop_vinfo, class loop *loop,
                                   gphi *phi)
 {
+  /* A nested cycle isn't vectorizable as first order recurrence.  */
+  if (LOOP_VINFO_LOOP (loop_vinfo) != loop)
+    return false;
+
   /* Ensure the loop latch definition is from within the loop.  */
   edge latch = loop_latch_edge (loop);
   tree ldef = PHI_ARG_DEF_FROM_EDGE (phi, latch);