public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-139] tree-optimization/99776 - relax condition on vector ctor element extract
Date: Tue, 27 Apr 2021 07:16:06 +0000 (GMT)	[thread overview]
Message-ID: <20210427071606.B25D7398407A@sourceware.org> (raw)

https://gcc.gnu.org/g:7d6bb80931b429631f63e0fd27bee95f32eb57a9

commit r12-139-g7d6bb80931b429631f63e0fd27bee95f32eb57a9
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Mar 26 09:50:03 2021 +0100

    tree-optimization/99776 - relax condition on vector ctor element extract
    
    This relaxes the condition for the match.pd pattern doing vector ctor
    element extracts to not require type identity but only size equality.
    Since we vectorize pointer data as unsigned integer data such mismatches
    have to be tolerated to optimize scalar code uses of vector results.
    
    2021-03-26  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/99776
            * match.pd (bit_field_ref (ctor)): Relax element extract
            type compatibility checks.
    
            * gcc.dg/tree-ssa/ssa-fre-91.c: New testcase.

Diff:
---
 gcc/match.pd                               | 18 +++++++++++++-----
 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-91.c | 17 +++++++++++++++++
 2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 66788ba6a86..bb1d6231de1 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6168,9 +6168,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 (simplify
  (BIT_FIELD_REF CONSTRUCTOR@0 @1 @2)
  (if (VECTOR_TYPE_P (TREE_TYPE (@0))
-      && (types_match (type, TREE_TYPE (TREE_TYPE (@0)))
+      && tree_fits_uhwi_p (TYPE_SIZE (type))
+      && ((tree_to_uhwi (TYPE_SIZE (type))
+	   == tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (@0)))))
           || (VECTOR_TYPE_P (type)
-	      && types_match (TREE_TYPE (type), TREE_TYPE (TREE_TYPE (@0))))))
+	      && (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)))
+		  == tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (@0))))))))
   (with
    {
      tree ctor = (TREE_CODE (@0) == SSA_NAME
@@ -6226,10 +6229,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 		  if (!CONSTANT_CLASS_P (e))
 		    constant_p = false;
 		}
-	      res = (constant_p ? build_vector_from_ctor (type, vals)
-		     : build_constructor (type, vals));
+	      tree evtype = (types_match (TREE_TYPE (type),
+					  TREE_TYPE (TREE_TYPE (ctor)))
+			     ? type
+			     : build_vector_type (TREE_TYPE (TREE_TYPE (ctor)),
+						  count));
+	      res = (constant_p ? build_vector_from_ctor (evtype, vals)
+		     : build_constructor (evtype, vals));
 	    }
-	    { res; })))))
+	    (view_convert { res; }))))))
       /* The bitfield references a single constructor element.  */
       (if (k.is_constant (&const_k)
 	   && idx + n <= (idx / const_k + 1) * const_k)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-91.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-91.c
new file mode 100644
index 00000000000..4999a3b66ab
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-91.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fdump-tree-fre4" } */
+
+extern void foo(void);
+
+static int a[2], b, *c[2];
+
+int main() {
+  for (b = 0; b < 2; b++)
+    c[b] = &a[1];
+  if (!c[0])
+    foo();
+  return 0;
+}
+
+/* Even when vectorizing we should eliminate the call to foo.  */
+/* { dg-final { scan-tree-dump-not "foo" "fre4" } } */


                 reply	other threads:[~2021-04-27  7:16 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=20210427071606.B25D7398407A@sourceware.org \
    --to=rguenth@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).