]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/120211 - constrain LOOP_VINFO_EARLY_BREAKS_LIVE_IVS more
authorRichard Biener <rguenther@suse.de>
Sun, 11 May 2025 12:03:12 +0000 (14:03 +0200)
committerRichard Biener <rguenther@suse.de>
Sun, 11 May 2025 13:39:51 +0000 (15:39 +0200)
The PR120089 fix added more PHIs to LOOP_VINFO_EARLY_BREAKS_LIVE_IVS
but not checking that we only add PHIs with a latch argument.  The
following adds this missing check.

PR tree-optimization/120211
* tree-vect-stmts.cc (vect_stmt_relevant_p): Only add PHIs
from the loop header to LOOP_VINFO_EARLY_BREAKS_LIVE_IVS.

* gcc.dg/vect/vect-early-break_135-pr120211.c: New testcase.
* gcc.dg/torture/pr120211-1.c: Likewise.

gcc/testsuite/gcc.dg/torture/pr120211-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-early-break_135-pr120211.c [new file with mode: 0644]
gcc/tree-vect-stmts.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr120211-1.c b/gcc/testsuite/gcc.dg/torture/pr120211-1.c
new file mode 100644 (file)
index 0000000..f9bc97c
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+
+int a, b, d;
+void e() {
+  do {
+    int f = 0;
+    while (1) {
+      int c = a;
+      for (; (c & 1) == 0; c = 1)
+        for (; c & 1;)
+          ;
+      if (a)
+        break;
+      f++;
+    }
+    b = f & 5;
+    if (b)
+      break;
+  } while (d++);
+}
diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_135-pr120211.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_135-pr120211.c
new file mode 100644 (file)
index 0000000..664b60d
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-add-options vect_early_break } */
+/* { dg-additional-options "-O3 -fno-tree-copy-prop -fno-tree-dominator-opts -fno-tree-loop-ivcanon -fno-tree-pre -fno-code-hoisting" } */
+
+int a, b[1];
+int main() {
+  int c = 0;
+  for (; c < 1; c++) {
+    while (a)
+      c++;
+    b[c] = 0;
+  }
+}
index efe6a2c9c4250ec07596ae46a676129289c4067a..bd390b26e0a30ea2a9bb503a3a96baafc0ef77e3 100644 (file)
@@ -424,6 +424,7 @@ vect_stmt_relevant_p (stmt_vec_info stmt_info, loop_vec_info loop_vinfo,
      alternate exit.  */
   if (LOOP_VINFO_EARLY_BREAKS (loop_vinfo)
       && is_a <gphi *> (stmt)
+      && gimple_bb (stmt) == LOOP_VINFO_LOOP (loop_vinfo)->header
       && ((! VECTORIZABLE_CYCLE_DEF (STMT_VINFO_DEF_TYPE (stmt_info))
          && ! *live_p)
          || STMT_VINFO_DEF_TYPE (stmt_info) == vect_induction_def))