aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2025-05-11 14:03:12 +0200
committerRichard Biener <rguenther@suse.de>2025-05-11 14:03:12 +0200
commit44cd55a1df897e3160cffeb10f96171bafc06400 (patch)
tree5d4c495755b05c9ee5c2e4b3f2e71c62171c3448
parent47e830211d39b5efb14144bbdaf8f2d83ba8375e (diff)
downloadgcc-44cd55a1df897e3160cffeb10f96171bafc06400.zip
gcc-44cd55a1df897e3160cffeb10f96171bafc06400.tar.gz
gcc-44cd55a1df897e3160cffeb10f96171bafc06400.tar.bz2
tree-optimization/120211 - constrain LOOP_VINFO_EARLY_BREAKS_LIVE_IVS more
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.
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr120211-1.c20
-rw-r--r--gcc/testsuite/gcc.dg/vect/vect-early-break_135-pr120211.c12
-rw-r--r--gcc/tree-vect-stmts.cc1
3 files changed, 33 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr120211-1.c b/gcc/testsuite/gcc.dg/torture/pr120211-1.c
new file mode 100644
index 0000000..f9bc97c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr120211-1.c
@@ -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
index 0000000..664b60d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_135-pr120211.c
@@ -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;
+ }
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 50d1abe..978a462 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -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))