public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/97760 - reduction paths with unhandled live stmt
@ 2020-11-10  9:17 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2020-11-10  9:17 UTC (permalink / raw)
  To: gcc-patches

This makes sure we reject reduction paths with a live stmt that
is not the last one altering the value.  This is because we do not
handle this in the epilogue unless there's a scalar epilogue loop.

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

2020-11-09  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/97760
	* tree-vect-loop.c (check_reduction_path): Reject
	reduction paths we do not handle in epilogue generation.

	* gcc.dg/vect/pr97760.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/pr97760.c | 26 ++++++++++++++++++++++++++
 gcc/tree-vect-loop.c                |  9 ++++++---
 2 files changed, 32 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr97760.c

diff --git a/gcc/testsuite/gcc.dg/vect/pr97760.c b/gcc/testsuite/gcc.dg/vect/pr97760.c
new file mode 100644
index 00000000000..da5ac937a43
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr97760.c
@@ -0,0 +1,26 @@
+#include "tree-vect.h"
+
+int b=1;
+static int *g = &b;
+
+void __attribute__((noipa))
+h (unsigned int n)
+{
+  int i = 3;
+  int f = 3;
+  for (; f <= 50; f += 4) {
+    i += 4;
+    *g = i;
+    i += n;
+  }
+}
+
+int main ()
+{
+  check_vect ();
+
+  h (9);
+  if (*g != 150 || b != 150)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 977633a3ce3..39b7319e825 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -3326,14 +3326,17 @@ pop:
 	  fail = true;
 	  break;
 	}
-      /* Check there's only a single stmt the op is used on inside
-         of the loop.  */
+      /* Check there's only a single stmt the op is used on.  For the
+	 not value-changing tail and the last stmt allow out-of-loop uses.
+	 ???  We could relax this and handle arbitrary live stmts by
+	 forcing a scalar epilogue for example.  */
       imm_use_iterator imm_iter;
       gimple *op_use_stmt;
       unsigned cnt = 0;
       FOR_EACH_IMM_USE_STMT (op_use_stmt, imm_iter, op)
 	if (!is_gimple_debug (op_use_stmt)
-	    && flow_bb_inside_loop_p (loop, gimple_bb (op_use_stmt)))
+	    && (*code != ERROR_MARK
+		|| flow_bb_inside_loop_p (loop, gimple_bb (op_use_stmt))))
 	  {
 	    /* We want to allow x + x but not x < 1 ? x : 2.  */
 	    if (is_gimple_assign (op_use_stmt)
-- 
2.26.2

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-10  9:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-10  9:17 [PATCH] tree-optimization/97760 - reduction paths with unhandled live stmt Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).