]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/102046 - fix SLP build from scalars with patterns
authorRichard Biener <rguenther@suse.de>
Wed, 25 Aug 2021 08:06:01 +0000 (10:06 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 6 Sep 2021 08:09:10 +0000 (10:09 +0200)
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.

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.

(cherry picked from commit 29c77454e5ab33ce06a741eacdfbd5348fbccc95)

gcc/testsuite/gcc.dg/vect/pr102046.c [new file with mode: 0644]
gcc/tree-vect-slp.c

diff --git a/gcc/testsuite/gcc.dg/vect/pr102046.c b/gcc/testsuite/gcc.dg/vect/pr102046.c
new file mode 100644 (file)
index 0000000..ae48b49
--- /dev/null
@@ -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;
+}
index ffecc9a7cd3e69516f61222fa25051ea9f43cd79..bae255e96d5937087210b0925e98da3b3d5887c2 100644 (file)
@@ -1819,6 +1819,10 @@ vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node,
              }
          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,