public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andre Simoes Dias Vieira <avieira@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-3413] vect: Fix vectype when widening container type in bitfield pattern [PR107326]
Date: Thu, 20 Oct 2022 14:55:01 +0000 (GMT)	[thread overview]
Message-ID: <20221020145501.BA4F0385043A@sourceware.org> (raw)

https://gcc.gnu.org/g:e10ca9544632dbff4759b4b92886cd96d0b9bdfe

commit r13-3413-ge10ca9544632dbff4759b4b92886cd96d0b9bdfe
Author: Andre Vieira <andre.simoesdiasvieira@arm.com>
Date:   Thu Oct 20 15:54:39 2022 +0100

    vect: Fix vectype when widening container type in bitfield pattern [PR107326]
    
    The 'vect_recog_bitfield_ref_pattern' was not correctly adapting the vectype
    when widening the container.
    
    gcc/ChangeLog:
    
            PR tree-optimization/107326
            * tree-vect-patterns.cc (vect_recog_bitfield_ref_pattern): Change
            vectype when widening container.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/vect/pr107326.c: New test.
            * gcc.dg/vect/vect-bitfield-read-7.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr107326.c             | 24 +++++++++++++
 gcc/testsuite/gcc.dg/vect/vect-bitfield-read-7.c | 43 ++++++++++++++++++++++++
 gcc/tree-vect-patterns.cc                        |  9 ++---
 3 files changed, 72 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr107326.c b/gcc/testsuite/gcc.dg/vect/pr107326.c
new file mode 100644
index 00000000000..333a515e741
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr107326.c
@@ -0,0 +1,24 @@
+/* PR107326 */
+/* { dg-do compile } */
+struct Gsymtab {
+  unsigned int : 8;
+  unsigned int visited_somewhere : 1;
+};
+
+extern struct Gsymtab glob_symtab[];
+
+int
+visit_children (int i)
+{
+  int numvisited = 0;
+
+  while (i < 1)
+    {
+      if (glob_symtab[i].visited_somewhere)
+        ++numvisited;
+
+      ++i;
+    }
+
+  return numvisited;
+}
diff --git a/gcc/testsuite/gcc.dg/vect/vect-bitfield-read-7.c b/gcc/testsuite/gcc.dg/vect/vect-bitfield-read-7.c
new file mode 100644
index 00000000000..3b505db2bd3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-bitfield-read-7.c
@@ -0,0 +1,43 @@
+/* { dg-require-effective-target vect_int } */
+
+#include <stdarg.h>
+#include "tree-vect.h"
+
+extern void abort(void);
+
+struct s {
+    unsigned i : 8;
+    char a : 4;
+};
+
+#define N 32
+#define ELT0 {0xFUL, 0}
+#define ELT1 {0xFUL, 1}
+#define ELT2 {0xFUL, 2}
+#define ELT3 {0xFUL, 3}
+#define RES 48
+struct s A[N]
+  = { ELT0, ELT1, ELT2, ELT3, ELT0, ELT1, ELT2, ELT3,
+      ELT0, ELT1, ELT2, ELT3, ELT0, ELT1, ELT2, ELT3,
+      ELT0, ELT1, ELT2, ELT3, ELT0, ELT1, ELT2, ELT3,
+      ELT0, ELT1, ELT2, ELT3, ELT0, ELT1, ELT2, ELT3};
+
+int __attribute__ ((noipa))
+f(struct s *ptr, unsigned n) {
+    int res = 0;
+    for (int i = 0; i < n; ++i)
+      res += ptr[i].a;
+    return res;
+}
+
+int main (void)
+{
+  check_vect ();
+
+  if (f(&A[0], N) != RES)
+    abort ();
+
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index d18e1e60996..777ba2f5903 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -1922,7 +1922,8 @@ vect_recog_bitfield_ref_pattern (vec_info *vinfo, stmt_vec_info stmt_info,
   tree ret = gimple_assign_lhs (first_stmt);
   tree ret_type = TREE_TYPE (ret);
   bool shift_first = true;
-  tree vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (container));
+  tree container_type = TREE_TYPE (container);
+  tree vectype = get_vectype_for_scalar_type (vinfo, container_type);
 
   /* We move the conversion earlier if the loaded type is smaller than the
      return type to enable the use of widening loads.  */
@@ -1933,15 +1934,15 @@ vect_recog_bitfield_ref_pattern (vec_info *vinfo, stmt_vec_info stmt_info,
 	= gimple_build_assign (vect_recog_temp_ssa_var (ret_type),
 			       NOP_EXPR, container);
       container = gimple_get_lhs (pattern_stmt);
-      append_pattern_def_seq (vinfo, stmt_info, pattern_stmt);
+      container_type = TREE_TYPE (container);
+      vectype = get_vectype_for_scalar_type (vinfo, container_type);
+      append_pattern_def_seq (vinfo, stmt_info, pattern_stmt, vectype);
     }
   else if (!useless_type_conversion_p (TREE_TYPE (container), ret_type))
     /* If we are doing the conversion last then also delay the shift as we may
        be able to combine the shift and conversion in certain cases.  */
     shift_first = false;
 
-  tree container_type = TREE_TYPE (container);
-
   /* If the only use of the result of this BIT_FIELD_REF + CONVERT is a
      PLUS_EXPR then do the shift last as some targets can combine the shift and
      add into a single instruction.  */

                 reply	other threads:[~2022-10-20 14:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221020145501.BA4F0385043A@sourceware.org \
    --to=avieira@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).