public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/112818 - re-instantiate vector type size check for bswap
@ 2023-12-04 13:25 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-12-04 13:25 UTC (permalink / raw)
  To: gcc-patches

For __builtin_bswap vectorization we still require an equal vector
type size.  Re-instantiate that check.

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

	PR tree-optimization/112818
	* tree-vect-stmts.cc (vectorizable_bswap): Check input and
	output vector types have the same size.

	* gcc.dg/vect/pr112818.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/pr112818.c | 34 ++++++++++++++++++++++++++++
 gcc/tree-vect-stmts.cc               |  9 ++++++++
 2 files changed, 43 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr112818.c

diff --git a/gcc/testsuite/gcc.dg/vect/pr112818.c b/gcc/testsuite/gcc.dg/vect/pr112818.c
new file mode 100644
index 00000000000..61a30a576b7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr112818.c
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+
+extern char tag_data[];
+struct pppoe_tag {
+    unsigned short tag_type;
+    unsigned short tag_len;
+};
+
+char code;
+int *add_tag_pack;
+void *add_tag_data;
+short e;
+long c, d;
+
+static int add_tag(int type, int len) {
+    short a, b;
+    struct pppoe_tag *tag = (struct pppoe_tag *)add_tag_pack;
+    if (e + len || len < 0)
+      return 1;
+    b = __builtin_bswap16(type);
+    tag->tag_type = b;
+    a = __builtin_bswap16(len);
+    tag->tag_len = a;
+    if (add_tag_data)
+      __builtin___memcpy_chk(tag_data, add_tag_data, len, c);
+    return 0;
+}
+void pppoe_serv_read() {
+    switch (code)
+  case 9: {
+	      add_tag(2, d);
+	      add_tag(0, 2);
+	  }
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 067abac3917..390c8472fd6 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -2976,6 +2976,15 @@ vectorizable_bswap (vec_info *vinfo,
 
   gcc_assert (ncopies >= 1);
 
+  if (TYPE_SIZE (vectype_in) != TYPE_SIZE (vectype))
+    {
+      if (dump_enabled_p ())
+	dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+			 "mismatched vector sizes %T and %T\n",
+			 vectype_in, vectype);
+      return false;
+    }
+
   tree char_vectype = get_same_sized_vectype (char_type_node, vectype_in);
   if (! char_vectype)
     return false;
-- 
2.35.3

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

only message in thread, other threads:[~2023-12-04 13:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-04 13:25 [PATCH] tree-optimization/112818 - re-instantiate vector type size check for bswap 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).