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] middle-end/105965 - add missing v_c_e <{ el }> simplification
Date: Tue, 14 Jun 2022 12:49:52 +0200 (CEST)	[thread overview]
Message-ID: <20220614104952.C0d_vqA6zJhb6O1albg7tUv3CgEcRQ34-cT6K-y_0qw@z> (raw)

When we got the simplification of bit-field-ref to view-convert
we lost the ability to detect FMAs since we cannot look through

  _1 = {_10};
  _11 = VIEW_CONVERT_EXPR<float>(_1);

the following amends the (view_convert CONSTRUCTOR) pattern
to handle this case.

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

2022-06-14  Richard Biener  <rguenther@suse.de>

	PR middle-end/105965
	* match.pd (view_convert CONSTRUCTOR): Handle single-element
	CTOR case.

	* gcc.target/i386/pr105965.c: New testcase.
---
 gcc/match.pd                             | 17 +++++++++++++----
 gcc/testsuite/gcc.target/i386/pr105965.c | 12 ++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr105965.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 44a385b912d..776c9c6489a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3669,12 +3669,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 	       && TYPE_UNSIGNED (TREE_TYPE (@1)))))
    (view_convert @1)))
 
-/* Simplify a view-converted empty constructor.  */
+/* Simplify a view-converted empty or single-element constructor.  */
 (simplify
   (view_convert CONSTRUCTOR@0)
-  (if (TREE_CODE (@0) != SSA_NAME
-       && CONSTRUCTOR_NELTS (@0) == 0)
-   { build_zero_cst (type); }))
+  (with
+   { tree ctor = (TREE_CODE (@0) == SSA_NAME
+		  ? gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0)) : @0); }
+   (switch
+    (if (CONSTRUCTOR_NELTS (ctor) == 0)
+     { build_zero_cst (type); })
+    (if (CONSTRUCTOR_NELTS (ctor) == 1
+	 && VECTOR_TYPE_P (TREE_TYPE (ctor))
+	 && operand_equal_p (TYPE_SIZE (type),
+			     TYPE_SIZE (TREE_TYPE
+			       (CONSTRUCTOR_ELT (ctor, 0)->value))))
+     (view_convert { CONSTRUCTOR_ELT (ctor, 0)->value; })))))
 
 /* Re-association barriers around constants and other re-association
    barriers can be removed.  */
diff --git a/gcc/testsuite/gcc.target/i386/pr105965.c b/gcc/testsuite/gcc.target/i386/pr105965.c
new file mode 100644
index 00000000000..5bb53790de8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr105965.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mfma -mfpmath=sse" } */
+
+typedef float v1sf __attribute__((vector_size(4)));
+
+v1sf
+foo43 (v1sf a, v1sf b, v1sf c)
+{
+  return a * b + c;
+}
+
+/* { dg-final { scan-assembler "fmadd" } } */
-- 
2.35.3

             reply	other threads:[~2022-06-14 10:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-14 10:49 Richard Biener [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-06-14 10:49 Richard Biener
2022-06-14 10:49 Richard Biener

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=20220614104952.C0d_vqA6zJhb6O1albg7tUv3CgEcRQ34-cT6K-y_0qw@z \
    --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).