public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/107686 - fix bitfield ref through vec_unpack optimization
Date: Wed, 16 Nov 2022 16:34:20 +0100 (CET)	[thread overview]
Message-ID: <20221116153421.1EE2513480@imap2.suse-dmz.suse.de> (raw)

The following propely restricts the bitfield access to integral types
when we look through VEC_UNPACK with the intent to emit a widening
conversion.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

	PR tree-optimization/107686
	* tree-ssa-forwprop.cc (optimize_vector_load): Restrict
	VEC_UNPACK support to integral typed bitfield refs.

	* gcc.dg/pr107686.c: New testcase.
---
 gcc/testsuite/gcc.dg/pr107686.c | 16 ++++++++++++++++
 gcc/tree-ssa-forwprop.cc        |  6 +++++-
 2 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr107686.c

diff --git a/gcc/testsuite/gcc.dg/pr107686.c b/gcc/testsuite/gcc.dg/pr107686.c
new file mode 100644
index 00000000000..2378103c555
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr107686.c
@@ -0,0 +1,16 @@
+/* { dg-do compile { target { dfp && longlong64 } } } */
+/* { dg-options "-O" } */
+/* { dg-additional-options "-mavx2" { target x86_64-*-* i?86-*-* } } */
+
+typedef _Decimal64 __attribute__((__vector_size__ (64))) D;
+typedef __INT32_TYPE__ __attribute__((__vector_size__ (32))) U;
+typedef __INT64_TYPE__ __attribute__((__vector_size__ (64))) V;
+
+U u;
+D d;
+
+void
+foo (void)
+{
+  d = d < (D) __builtin_convertvector (u, V);
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 7c7942600ef..429f77f199c 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -3162,7 +3162,11 @@ optimize_vector_load (gimple_stmt_iterator *gsi)
 	      && (def == lhs
 		  || (known_eq (bit_field_size (use_rhs), def_eltsize)
 		      && constant_multiple_p (bit_field_offset (use_rhs),
-					      def_eltsize))))
+					      def_eltsize)
+		      /* We can simulate the VEC_UNPACK_{HI,LO}_EXPR
+			 via a NOP_EXPR only for integral types.
+			 ???  Support VEC_UNPACK_FLOAT_{HI,LO}_EXPR.  */
+		      && INTEGRAL_TYPE_P (TREE_TYPE (use_rhs)))))
 	    {
 	      bf_stmts.safe_push (use_stmt);
 	      continue;
-- 
2.35.3

                 reply	other threads:[~2022-11-16 15:34 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=20221116153421.1EE2513480@imap2.suse-dmz.suse.de \
    --to=rguenther@suse.de \
    --cc=gcc-patches@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).