+2016-12-14 Uros Bizjak <ubizjak@gmail.com>
+
+ PR target/59874
+ * config/i386/i386-builtin.def: Add __builtin_clzs and __builtin_ctzs.
+ (ix86_fold_builtin): Handle IX86_BUILTIN_CTZS and IX86_BUILTIN_CLZS.
+ * config/i386/i386.md (*ctzhi2): New insn_and_split pattern.
+ (*clzhi2): Ditto.
+
2016-12-14 Jakub Jelinek <jakub@redhat.com>
PR debug/77844
/* LZCNT */
BDESC (OPTION_MASK_ISA_LZCNT, CODE_FOR_lzcnt_hi, "__builtin_ia32_lzcnt_u16", IX86_BUILTIN_LZCNT16, UNKNOWN, (int) UINT16_FTYPE_UINT16)
+/* Same as above, for backward compatibility. */
+BDESC (OPTION_MASK_ISA_LZCNT, CODE_FOR_lzcnt_hi, "__builtin_clzs", IX86_BUILTIN_CLZS, UNKNOWN, (int) UINT16_FTYPE_UINT16)
BDESC (OPTION_MASK_ISA_LZCNT, CODE_FOR_lzcnt_si, "__builtin_ia32_lzcnt_u32", IX86_BUILTIN_LZCNT32, UNKNOWN, (int) UINT_FTYPE_UINT)
BDESC (OPTION_MASK_ISA_LZCNT | OPTION_MASK_ISA_64BIT, CODE_FOR_lzcnt_di, "__builtin_ia32_lzcnt_u64", IX86_BUILTIN_LZCNT64, UNKNOWN, (int) UINT64_FTYPE_UINT64)
BDESC (OPTION_MASK_ISA_BMI | OPTION_MASK_ISA_64BIT, CODE_FOR_bmi_bextr_di, "__builtin_ia32_bextr_u64", IX86_BUILTIN_BEXTR64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64)
BDESC (OPTION_MASK_ISA_BMI, CODE_FOR_bmi_tzcnt_hi, "__builtin_ia32_tzcnt_u16", IX86_BUILTIN_TZCNT16, UNKNOWN, (int) UINT16_FTYPE_UINT16)
+/* Same as above, for backward compatibility. */
+BDESC (OPTION_MASK_ISA_BMI, CODE_FOR_bmi_tzcnt_hi, "__builtin_ctzs", IX86_BUILTIN_CTZS, UNKNOWN, (int) UINT16_FTYPE_UINT16)
BDESC (OPTION_MASK_ISA_BMI, CODE_FOR_bmi_tzcnt_si, "__builtin_ia32_tzcnt_u32", IX86_BUILTIN_TZCNT32, UNKNOWN, (int) UINT_FTYPE_UINT)
BDESC (OPTION_MASK_ISA_BMI | OPTION_MASK_ISA_64BIT, CODE_FOR_bmi_tzcnt_di, "__builtin_ia32_tzcnt_u64", IX86_BUILTIN_TZCNT64, UNKNOWN, (int) UINT64_FTYPE_UINT64)
}
case IX86_BUILTIN_TZCNT16:
+ case IX86_BUILTIN_CTZS:
case IX86_BUILTIN_TZCNT32:
case IX86_BUILTIN_TZCNT64:
gcc_assert (n_args == 1);
{
tree type = TREE_TYPE (TREE_TYPE (fndecl));
tree arg = args[0];
- if (fn_code == IX86_BUILTIN_TZCNT16)
+ if (fn_code == IX86_BUILTIN_TZCNT16
+ || fn_code == IX86_BUILTIN_CTZS)
arg = fold_convert (short_unsigned_type_node, arg);
if (integer_zerop (arg))
return build_int_cst (type, TYPE_PRECISION (TREE_TYPE (arg)));
break;
case IX86_BUILTIN_LZCNT16:
+ case IX86_BUILTIN_CLZS:
case IX86_BUILTIN_LZCNT32:
case IX86_BUILTIN_LZCNT64:
gcc_assert (n_args == 1);
{
tree type = TREE_TYPE (TREE_TYPE (fndecl));
tree arg = args[0];
- if (fn_code == IX86_BUILTIN_LZCNT16)
+ if (fn_code == IX86_BUILTIN_LZCNT16
+ || fn_code == IX86_BUILTIN_CLZS)
arg = fold_convert (short_unsigned_type_node, arg);
if (integer_zerop (arg))
return build_int_cst (type, TYPE_PRECISION (TREE_TYPE (arg)));
(match_operand:SWI48 1 "nonimmediate_operand")))
(clobber (reg:CC FLAGS_REG))])])
+(define_insn_and_split "*ctzhi2"
+ [(set (match_operand:SI 0 "register_operand")
+ (ctz:SI
+ (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand"))))
+ (clobber (reg:CC FLAGS_REG))]
+ "TARGET_BMI
+ && can_create_pseudo_p ()"
+ "#"
+ "&& 1"
+ [(const_int 0)]
+{
+ rtx tmp = gen_reg_rtx (HImode);
+
+ emit_insn (gen_bmi_tzcnt_hi (tmp, operands[1]));
+ emit_insn (gen_zero_extendhisi2 (operands[0], tmp));
+ DONE;
+})
+
; False dependency happens when destination is only updated by tzcnt,
; lzcnt or popcnt. There is no false dependency when destination is
; also used in source.
(clobber (reg:CC FLAGS_REG))])]
"TARGET_LZCNT")
+(define_insn_and_split "*clzhi2"
+ [(set (match_operand:SI 0 "register_operand")
+ (clz:SI
+ (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand"))))
+ (clobber (reg:CC FLAGS_REG))]
+ "TARGET_LZCNT
+ && can_create_pseudo_p ()"
+ "#"
+ "&& 1"
+ [(const_int 0)]
+{
+ rtx tmp = gen_reg_rtx (HImode);
+
+ emit_insn (gen_lzcnt_hi (tmp, operands[1]));
+ emit_insn (gen_zero_extendhisi2 (operands[0], tmp));
+ DONE;
+})
+
+; False dependency happens when destination is only updated by tzcnt,
+; lzcnt or popcnt. There is no false dependency when destination is
+; also used in source.
(define_insn_and_split "*clz<mode>2_lzcnt_falsedep_1"
[(set (match_operand:SWI48 0 "register_operand" "=r")
(clz:SWI48
+2016-12-14 Uros Bizjak <ubizjak@gmail.com>
+
+ PR target/59874
+ * gcc.target/i386/pr59874-1.c: New test.
+ * gcc.target/i386/pr59874-2.c: Ditto.
+
2016-12-14 David Edelsohn <dje.gcc@gmail.com>
* gcc.dg/torture/pr78515.c: Add -Wno-psabi for AIX.
--- /dev/null
+/* PR target/59874 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mbmi -masm=att" } */
+/* { dg-final { scan-assembler "tzcntw" } } */
+
+unsigned int
+foo (unsigned short x)
+{
+ return x ? __builtin_ctz (x) : 16U;
+}
--- /dev/null
+/* PR target/59874 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mlzcnt -masm=att" } */
+/* { dg-final { scan-assembler "lzcntw" } } */
+
+unsigned int
+foo (unsigned short x)
+{
+ return x ? __builtin_clz (x) : 16U;
+}