public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/102046 - fix SLP build from scalars with patterns
@ 2021-08-25  9:31 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-08-25  9:31 UTC (permalink / raw)
  To: gcc-patches

When we swap operands for SLP builds we lose track where exactly
pattern defs are - but we fail to update the any_pattern member
of the operands info.  Do so conservatively.

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

2021-08-25  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/102046
	* tree-vect-slp.c (vect_build_slp_tree_2): Conservatively
	update ->any_pattern when swapping operands.

	* gcc.dg/vect/pr102046.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/pr102046.c | 19 +++++++++++++++++++
 gcc/tree-vect-slp.c                  |  4 ++++
 2 files changed, 23 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr102046.c

diff --git a/gcc/testsuite/gcc.dg/vect/pr102046.c b/gcc/testsuite/gcc.dg/vect/pr102046.c
new file mode 100644
index 00000000000..ae48b497dc0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr102046.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O3 -fvect-cost-model=dynamic" } */
+/* { dg-additional-options "-march=btver2" { target x86_64-*-* i?86-*-* } } */
+
+struct S
+{
+  unsigned a, b;
+};
+
+struct S g;
+
+void
+foo (struct S *o)
+{
+  struct S s = g;
+  s.b *= 3;
+  s.a -= s.a / 2;
+  *o = s;
+}
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index edc11c62793..4d688c7a267 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -2311,6 +2311,10 @@ out:
 	      }
 	  if (dump_enabled_p ())
 	    dump_printf (MSG_NOTE, "\n");
+	  /* After swapping some operands we lost track whether an
+	     operand has any pattern defs so be conservative here.  */
+	  if (oprnds_info[0]->any_pattern || oprnds_info[1]->any_pattern)
+	    oprnds_info[0]->any_pattern = oprnds_info[1]->any_pattern = true;
 	  /* And try again with scratch 'matches' ... */
 	  bool *tem = XALLOCAVEC (bool, group_size);
 	  if ((child = vect_build_slp_tree (vinfo, oprnd_info->def_stmts,
-- 
2.31.1

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

only message in thread, other threads:[~2021-08-25  9:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-25  9:31 [PATCH] tree-optimization/102046 - fix SLP build from scalars with patterns 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).