===================================================================
@@ -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
===================================================================
@@ -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);
+}