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 <[email protected]>
* config/i386/i386.md (*popcounthi2_1): New insn_and_split pattern.
testsuite/ChangeLog:
2016-12-19 Uros Bizjak <[email protected]>
* gcc.target/i386/pr59874-3.c: New test.
Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.
Committed to mainline SVN.
Uros.
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);
+}