public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, i386] Add *popcounthi2_1 insn and splitter
@ 2016-12-19 20:27 Uros Bizjak
  0 siblings, 0 replies; only message in thread
From: Uros Bizjak @ 2016-12-19 20:27 UTC (permalink / raw)
  To: gcc-patches

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

Hello!

This patch just adds missing popcounthi2 insn and splitter to enable
POPCNTW generation from _builtin_popcount builtin with zero-extended
unsigned short argument.

2016-12-19  Uros Bizjak  <ubizjak@gmail.com>

    * config/i386/i386.md (*popcounthi2_1): New insn_and_split pattern.

testsuite/ChangeLog:

2016-12-19  Uros Bizjak  <ubizjak@gmail.com>

    * gcc.target/i386/pr59874-3.c: New test.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Committed to mainline SVN.

Uros.

[-- Attachment #2: p.diff.txt --]
[-- Type: text/plain, Size: 1286 bytes --]

Index: config/i386/i386.md
===================================================================
--- config/i386/i386.md	(revision 243799)
+++ config/i386/i386.md	(working copy)
@@ -13221,6 +13221,24 @@
    (set_attr "type" "bitmanip")
    (set_attr "mode" "<MODE>")])
 
+(define_insn_and_split "*popcounthi2_1"
+  [(set (match_operand:SI 0 "register_operand")
+	(popcount:SI
+	  (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand"))))
+   (clobber (reg:CC FLAGS_REG))]
+  "TARGET_POPCNT
+   && can_create_pseudo_p ()"
+  "#"
+  "&& 1"
+  [(const_int 0)]
+{
+  rtx tmp = gen_reg_rtx (HImode);
+
+  emit_insn (gen_popcounthi2 (tmp, operands[1]));
+  emit_insn (gen_zero_extendhisi2 (operands[0], tmp));
+  DONE;
+})
+
 (define_insn "popcounthi2"
   [(set (match_operand:HI 0 "register_operand" "=r")
 	(popcount:HI
Index: testsuite/gcc.target/i386/pr59874-3.c
===================================================================
--- testsuite/gcc.target/i386/pr59874-3.c	(nonexistent)
+++ testsuite/gcc.target/i386/pr59874-3.c	(working copy)
@@ -0,0 +1,10 @@
+/* PR target/59874 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mpopcnt -masm=att" } */
+/* { dg-final { scan-assembler "popcntw" } } */
+
+unsigned int
+foo (unsigned short x)
+{
+  return __builtin_popcount (x);
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-12-19 20:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-19 20:27 [PATCH, i386] Add *popcounthi2_1 insn and splitter Uros Bizjak

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).