* [PATCH] tree-optimization/114464 - verify types in recurrence vectorization
@ 2024-03-26 9:37 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2024-03-26 9:37 UTC (permalink / raw)
To: gcc-patches
The following adds missing verification of vector type compatibility
to recurrence vectorization.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR tree-optimization/114464
* tree-vect-loop.cc (vectorizable_recurr): Verify the latch
vector type is compatible with what we chose for the recurrence.
* g++.dg/vect/pr114464.cc: New testcase.
---
gcc/testsuite/g++.dg/vect/pr114464.cc | 11 +++++++++++
gcc/tree-vect-loop.cc | 22 ++++++++++++++++++++++
2 files changed, 33 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/vect/pr114464.cc
diff --git a/gcc/testsuite/g++.dg/vect/pr114464.cc b/gcc/testsuite/g++.dg/vect/pr114464.cc
new file mode 100644
index 00000000000..0d872aae9d4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/pr114464.cc
@@ -0,0 +1,11 @@
+// { dg-do compile }
+
+void h(unsigned char *scratch, bool carry)
+{
+ for (int i = 0; i < 16; i++) {
+ bool b = scratch[i] <<= 1;
+ if (carry)
+ scratch[i] |= 1;
+ carry = b;
+ }
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 302c92e6f31..42e78cc9c32 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -9212,6 +9212,28 @@ vectorizable_recurr (loop_vec_info loop_vinfo, stmt_vec_info stmt_info,
return false;
}
}
+
+ /* Verify we have set up compatible types. */
+ edge le = loop_latch_edge (LOOP_VINFO_LOOP (loop_vinfo));
+ tree latch_vectype = NULL_TREE;
+ if (slp_node)
+ {
+ slp_tree latch_def = SLP_TREE_CHILDREN (slp_node)[le->dest_idx];
+ latch_vectype = SLP_TREE_VECTYPE (latch_def);
+ }
+ else
+ {
+ tree latch_def = PHI_ARG_DEF_FROM_EDGE (phi, le);
+ if (TREE_CODE (latch_def) == SSA_NAME)
+ {
+ stmt_vec_info latch_def_info = loop_vinfo->lookup_def (latch_def);
+ latch_def_info = vect_stmt_to_vectorize (latch_def_info);
+ latch_vectype = STMT_VINFO_VECTYPE (latch_def_info);
+ }
+ }
+ if (!types_compatible_p (latch_vectype, vectype))
+ return false;
+
/* The recurrence costs the initialization vector and one permute
for each copy. */
unsigned prologue_cost = record_stmt_cost (cost_vec, 1, scalar_to_vec,
--
2.35.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-03-26 9:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-26 9:37 [PATCH] tree-optimization/114464 - verify types in recurrence vectorization 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).