]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/116879 - failure to recognize non-empty latch
authorRichard Biener <rguenther@suse.de>
Mon, 30 Sep 2024 11:38:28 +0000 (13:38 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Sun, 13 Oct 2024 09:19:45 +0000 (11:19 +0200)
When we relaxed the vectorizers constraint on loop structure verifying
the emptiness of the latch became too lose as can be seen in the case
for PR116879 where the latch effectively contains two basic-blocks
which one being an unmerged forwarder that's not empty.

PR tree-optimization/116879
* tree-vect-loop.cc (vect_analyze_loop_form): Scan all
blocks that form the latch.

* gcc.dg/pr116879.c: New testcase.

(cherry picked from commit 18e905b461a7138185cf4f0efde4a4e1214fb798)

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

diff --git a/gcc/testsuite/gcc.dg/pr116879.c b/gcc/testsuite/gcc.dg/pr116879.c
new file mode 100644 (file)
index 0000000..73ddb2b
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-vectorize -fallow-store-data-races -fno-tree-ch -ftree-loop-distribution" } */
+
+static int b;
+int *a, c, *d = &c;
+int main() {
+  int e = 0;
+  for (; e < 8; e = (char)(e + 1)) {
+    int *f = &b, g[8], h = 0;
+    for (; h < 8; h++)
+      g[h] = 0;
+    --*f != (*d = g[0] || a);
+  }
+  return 0;
+}
index dcd61292caf1dda3b65f9411ca321ad27b582e81..d5504930a99dec575189a28b8f1abef24cca77bc 100644 (file)
@@ -1848,10 +1848,17 @@ vect_analyze_loop_form (class loop *loop, vect_loop_form_info *info)
                                   " too many incoming edges.\n");
 
   /* We assume that the latch is empty.  */
-  if (!empty_block_p (loop->latch)
-      || !gimple_seq_empty_p (phi_nodes (loop->latch)))
-    return opt_result::failure_at (vect_location,
-                                  "not vectorized: latch block not empty.\n");
+  basic_block latch = loop->latch;
+  do
+    {
+      if (!empty_block_p (latch)
+         || !gimple_seq_empty_p (phi_nodes (latch)))
+       return opt_result::failure_at (vect_location,
+                                      "not vectorized: latch block not "
+                                      "empty.\n");
+      latch = single_pred (latch);
+    }
+  while (single_succ_p (latch));
 
   /* Make sure there is no abnormal exit.  */
   auto_vec<edge> exits = get_loop_exit_edges (loop);