public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Roger Sayle" <roger@nextmovesoftware.com>
To: <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Simplify vec_unpack of uniform_vector_p constructors in match.pd.
Date: Sat, 21 May 2022 16:31:27 +0100	[thread overview]
Message-ID: <008401d86d27$d74f9a20$85eece60$@nextmovesoftware.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1157 bytes --]


This patch simplifies vec_unpack_hi_expr/vec_unpack_lo_expr of a uniform
constructor or vec_duplicate operand.  The motivation is from PR 105621
where after optimization, we're left with:

  vect_cst__21 = {c_8(D), c_8(D), c_8(D), c_8(D)};
  vect_iftmp.7_4 = [vec_unpack_hi_expr] vect_cst__21;

It turns out that there are no constant folding/simplification patterns
in match.pd, but the above can be simplified further to the equivalent:

  _20 = (long int) c_8(D);
  vect_iftmp.7_4 = [vec_duplicate_expr] _20;

which on x86-64 results in one less instruction, replacing pshufd $0
then punpackhq, with punpcklqdq.  This transformation is also useful
for helping CSE to spot that unpack_hi and unpack_lo are equivalent.

This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
and make -k check with no new failures.  Ok for mainline?


2022-05-21  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
        * match.pd (simplify vec_unpack_hi): Simplify VEC_UNPACK_*_EXPR
        of uniform vector constructors and vec_duplicate.

gcc/testsuite/ChangeLog
        * g++.dg/vect/pr105621.cc: New test case.


Thanks in advance,
Roger
--


[-- Attachment #2: patchfb3.txt --]
[-- Type: text/plain, Size: 1609 bytes --]

diff --git a/gcc/match.pd b/gcc/match.pd
index c2fed9b..753c392 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -7800,6 +7800,22 @@ and,
  (if (TREE_CODE (@0) == SSA_NAME && num_imm_uses (@0) == 2)
   (minus (mult (vec_perm @1 @1 @3) @2) @4)))
 
+/* VEC_UNPACK_LO_EXPR and friends.  */
+(for unpack (vec_unpack_lo vec_unpack_float_lo vec_unpack_fix_trunc_lo
+	     vec_unpack_hi vec_unpack_float_hi vec_unpack_fix_trunc_hi)
+     opcode (convert float fix_trunc convert float fix_trunc)
+ (simplify
+  (unpack CONSTRUCTOR@0)
+  (with { tree ctor = (TREE_CODE (@0) == SSA_NAME
+		    ? gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0)) : @0);
+	  tree elt = uniform_vector_p (ctor);
+	  tree eltype = TREE_TYPE (type); }
+   (if (elt)
+    (vec_duplicate (opcode:eltype { elt; })))))
+ (simplify
+  (unpack (vec_duplicate @0))
+  (with { tree eltype = TREE_TYPE (type); }
+   (vec_duplicate (opcode:eltype @0)))))
 
 /* Match count trailing zeroes for simplify_count_trailing_zeroes in fwprop.
    The canonical form is array[((x & -x) * C) >> SHIFT] where C is a magic
diff --git a/gcc/testsuite/g++.dg/vect/pr105621.cc b/gcc/testsuite/g++.dg/vect/pr105621.cc
new file mode 100644
index 0000000..98e8fcd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/pr105621.cc
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+bool d;
+
+void test(unsigned short a, int b, unsigned c) {
+  for (int i = 2; i < 24; i += 3)
+    d = b ? a ? c : 2086607777901731118 : 0;
+}
+
+/* { dg-final { scan-tree-dump-not "vec_unpack" "optimized" } } */

             reply	other threads:[~2022-05-21 15:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-21 15:31 Roger Sayle [this message]
2022-05-23 10:49 ` Richard Biener
2022-06-06  9:06   ` Richard Sandiford
2022-06-13  9:52     ` 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='008401d86d27$d74f9a20$85eece60$@nextmovesoftware.com' \
    --to=roger@nextmovesoftware.com \
    --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).