public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/114435 - pcom left around copies confusing SLP
@ 2024-05-29 10:57 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2024-05-29 10:57 UTC (permalink / raw)
  To: gcc-patches

The following arranges for the pre-SLP vectorization scalar cleanup
to be run when predictive commoning was applied to a loop in the
function.  This is similar to the complete unroll situation and
facilitating SLP vectorization.  Avoiding the SSA copies in predictive
commoning itself isn't easy (and predcom also sometimes unrolls,
asking for scalar cleanup).

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

	PR tree-optimization/114435
	* tree-predcom.cc (tree_predictive_commoning): Queue
	the next scalar cleanup sub-pipeline to be run when we
	did something.

	* gcc.dg/vect/bb-slp-pr114435.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/bb-slp-pr114435.c | 37 +++++++++++++++++++++
 gcc/tree-predcom.cc                         |  3 ++
 2 files changed, 40 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/vect/bb-slp-pr114435.c

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr114435.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr114435.c
new file mode 100644
index 00000000000..d1eecf7979a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr114435.c
@@ -0,0 +1,37 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_double } */
+/* Predictive commining is supposed to happen.  */
+/* { dg-additional-options "-O3 -fdump-tree-pcom" } */
+
+struct res {
+    double r0;
+    double r1;
+    double r2;
+    double r3;
+};
+
+struct pxl {
+    double v0;
+    double v1;
+    double v2;
+    double v3;
+};
+
+#define IS_NAN(x) ((x) == (x))
+
+void fold(struct res *r, struct pxl *in, double k, int sz)
+{
+  int i;
+
+  for (i = 0; i < sz; i++) {
+      if (IS_NAN(k)) continue;
+      r->r0 += in[i].v0 * k;
+      r->r1 += in[i].v1 * k;
+      r->r2 += in[i].v2 * k;
+      r->r3 += in[i].v3 * k;
+  }
+}
+
+/* { dg-final { scan-tree-dump "# r__r0_lsm\[^\r\n\]* = PHI" "pcom" } } */
+/* { dg-final { scan-tree-dump "optimized: basic block part vectorized" "slp1" } } */
+/* { dg-final { scan-tree-dump "# vect\[^\r\n\]* = PHI" "slp1" } } */
diff --git a/gcc/tree-predcom.cc b/gcc/tree-predcom.cc
index 75a4c85164c..9844fee1e97 100644
--- a/gcc/tree-predcom.cc
+++ b/gcc/tree-predcom.cc
@@ -3522,6 +3522,9 @@ tree_predictive_commoning (bool allow_unroll_p)
 	}
     }
 
+  if (ret != 0)
+    cfun->pending_TODOs |= PENDING_TODO_force_next_scalar_cleanup;
+
   return ret;
 }
 
-- 
2.35.3

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

only message in thread, other threads:[~2024-05-29 10:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-29 10:57 [PATCH] tree-optimization/114435 - pcom left around copies confusing SLP 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).