tree-optimization/99880 - avoid vectorizing irrelevant PHI backedge defs

Message ID nycvar.YFH.7.76.2104061420090.4860@elmra.sevgm.obk
State New
Headers show
Series
  • tree-optimization/99880 - avoid vectorizing irrelevant PHI backedge defs
Related show

Commit Message

Richard Biener April 6, 2021, 12:20 p.m.
This adds a relevancy check before trying to set the vector def of
a backedge in an unvectorized PHI.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2021-04-06  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/99880
	* tree-vect-loop.c (maybe_set_vectorized_backedge_value): Only
	set vectorized defs of relevant PHIs.

	* gcc.dg/torture/pr99880.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr99880.c | 22 ++++++++++++++++++++++
 gcc/tree-vect-loop.c                   |  1 +
 2 files changed, 23 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr99880.c

-- 
2.26.2

Patch

diff --git a/gcc/testsuite/gcc.dg/torture/pr99880.c b/gcc/testsuite/gcc.dg/torture/pr99880.c
new file mode 100644
index 00000000000..7e0989987d7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr99880.c
@@ -0,0 +1,22 @@ 
+/* { dg-do compile } */
+/* { dg-additional-options "-ftree-vectorize" } */
+
+unsigned a;
+int b, c, d, e;
+void f() {
+  b = 5;
+  for (; b <= 51; b++)
+    ;
+  unsigned int g = -8;
+  while (g) {
+    g += 5;
+    int h = 10;
+    do {
+      h -= a = 1;
+      for (; a; a++)
+        ;
+      c *= c >= d >= b;
+    } while (h);
+    c -= e;
+  }
+}
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 38d96fc1634..4e928c65b31 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -9148,6 +9148,7 @@  maybe_set_vectorized_backedge_value (loop_vec_info loop_vinfo,
     if (gphi *phi = dyn_cast <gphi *> (USE_STMT (use_p)))
       if (gimple_bb (phi)->loop_father->header == gimple_bb (phi)
 	  && (phi_info = loop_vinfo->lookup_stmt (phi))
+	  && STMT_VINFO_RELEVANT_P (phi_info)
 	  && VECTORIZABLE_CYCLE_DEF (STMT_VINFO_DEF_TYPE (phi_info))
 	  && STMT_VINFO_REDUC_TYPE (phi_info) != FOLD_LEFT_REDUCTION
 	  && STMT_VINFO_REDUC_TYPE (phi_info) != EXTRACT_LAST_REDUCTION)