diff mbox series

tree-optimization/116658 - latent issue in vect_is_slp_load_node

Message ID 20240910094729.3438B3858C98@sourceware.org
State New
Headers show
Series tree-optimization/116658 - latent issue in vect_is_slp_load_node | expand

Commit Message

Richard Biener Sept. 10, 2024, 9:47 a.m. UTC
Permute nodes do not have a representative so we have to guard
vect_is_slp_load_node against those.

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

	PR tree-optimization/116658
	* tree-vect-slp.cc (vect_is_slp_load_node): Make sure
	node isn't a permute.

	* g++.dg/vect/pr116658.cc: New testcase.
---
 gcc/testsuite/g++.dg/vect/pr116658.cc | 58 +++++++++++++++++++++++++++
 gcc/tree-vect-slp.cc                  |  7 ++--
 2 files changed, 62 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/vect/pr116658.cc
diff mbox series

Patch

diff --git a/gcc/testsuite/g++.dg/vect/pr116658.cc b/gcc/testsuite/g++.dg/vect/pr116658.cc
new file mode 100644
index 00000000000..c3ff23a2b60
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/pr116658.cc
@@ -0,0 +1,58 @@ 
+// { dg-do compile }
+// { dg-require-effective-target c++11 }
+// { dg-additional-options "-O3" }
+// { dg-additional-options "-mavx512f" { target avx512f } }
+
+struct bb {
+  bb operator+=(bb bc) {
+      bd[0] += bc.bd[0];
+    return *this;
+  }
+  bb operator-=(bb bc) {
+      bd[0] -= bc.bd[0];
+    return *this;
+  }
+  bb operator*=(double be) {
+      bd[0] *= be;
+    return *this;
+  }
+  double bd[1];
+};
+
+bb operator+(bb n, bb v) {
+  bb bf = n;
+  return bf += v;
+}
+
+bb operator-(bb n, bb v) {
+  bb bf = n;
+  return bf -= v;
+}
+bb operator*(double n, bb v) {
+  bb bf = v;
+  return bf *= n;
+}
+
+using az = bb;
+struct cc {
+  void apply(bb *ci) {
+  bb xm[1];
+  for (int cm = 0; cm < 2; ++cm) {
+    az cn, co = cv[cm] * xm[0];
+    ci[cm] = cn + co;
+    ci[-1] = cn - co;
+  }
+  }
+  double *cu;
+  double *cv;
+};
+void dc(unsigned de, int di, az *dk, az *dl, cc dh) {
+  for (int c; c < 1024; ++c) {
+    if (de & 1)
+      dh.apply(dk);
+    if (de & 2)
+      dh.apply(dl);
+    dk += di;
+    dl += di;
+  }
+}
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 0fb17340bd3..31c7e20f8c9 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -3265,9 +3265,10 @@  calculate_unrolling_factor (poly_uint64 nunits, unsigned int group_size)
 static inline bool
 vect_is_slp_load_node  (slp_tree root)
 {
-  return SLP_TREE_DEF_TYPE (root) == vect_internal_def
-	 && STMT_VINFO_GROUPED_ACCESS (SLP_TREE_REPRESENTATIVE (root))
-	 && DR_IS_READ (STMT_VINFO_DATA_REF (SLP_TREE_REPRESENTATIVE (root)));
+  return (SLP_TREE_CODE (root) != VEC_PERM_EXPR
+	  && SLP_TREE_DEF_TYPE (root) == vect_internal_def
+	  && STMT_VINFO_GROUPED_ACCESS (SLP_TREE_REPRESENTATIVE (root))
+	  && DR_IS_READ (STMT_VINFO_DATA_REF (SLP_TREE_REPRESENTATIVE (root))));
 }