diff mbox

[i386] : Put back __builtin_clzs and __builtin_ctzs

Message ID CAFULd4aCMb62qDhLV8Std66An7CGQpA2PNwYx3GqWRxpEjZsdg@mail.gmail.com
State New
Headers show

Commit Message

Uros Bizjak Dec. 14, 2016, 3:30 p.m. UTC
Apparently, Qt source uses these two builtins. As the removal brings
much pain, I'd like to commit the following patch to restore
__builtin_clzs and __builtin_ctzs on gcc-6 branch.

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

    PR target/59874
    * config/i386/i386.c (enum ix86_builtins): Add IX86_BUILTIN_CLZS
    and IX86_BUILTIN_CTZS.
    (bdesc_args): Add __builtin_clzs and __builtin_ctzs.
    (ix86_fold_builtin): Handle IX86_BUILTIN_CTZS and IX86_BUILTIN_CLZS.

Bootstrapped and regression tested on x86_64-linux-gnu.

I have also checked that patched gcc emits the same code as before.

Uros.

Comments

Jakub Jelinek Dec. 14, 2016, 3:33 p.m. UTC | #1
On Wed, Dec 14, 2016 at 04:30:39PM +0100, Uros Bizjak wrote:
> Apparently, Qt source uses these two builtins. As the removal brings
> much pain, I'd like to commit the following patch to restore
> __builtin_clzs and __builtin_ctzs on gcc-6 branch.
> 
> 2016-12-14  Uros Bizjak  <ubizjak@gmail.com>
> 
>     PR target/59874
>     * config/i386/i386.c (enum ix86_builtins): Add IX86_BUILTIN_CLZS
>     and IX86_BUILTIN_CTZS.
>     (bdesc_args): Add __builtin_clzs and __builtin_ctzs.
>     (ix86_fold_builtin): Handle IX86_BUILTIN_CTZS and IX86_BUILTIN_CLZS.
> 
> Bootstrapped and regression tested on x86_64-linux-gnu.

Ok for 6.  For 7 we ask them to change it to the new builtins?

	Jakub
Uros Bizjak Dec. 14, 2016, 3:39 p.m. UTC | #2
On Wed, Dec 14, 2016 at 4:33 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Wed, Dec 14, 2016 at 04:30:39PM +0100, Uros Bizjak wrote:
>> Apparently, Qt source uses these two builtins. As the removal brings
>> much pain, I'd like to commit the following patch to restore
>> __builtin_clzs and __builtin_ctzs on gcc-6 branch.
>>
>> 2016-12-14  Uros Bizjak  <ubizjak@gmail.com>
>>
>>     PR target/59874
>>     * config/i386/i386.c (enum ix86_builtins): Add IX86_BUILTIN_CLZS
>>     and IX86_BUILTIN_CTZS.
>>     (bdesc_args): Add __builtin_clzs and __builtin_ctzs.
>>     (ix86_fold_builtin): Handle IX86_BUILTIN_CTZS and IX86_BUILTIN_CLZS.
>>
>> Bootstrapped and regression tested on x86_64-linux-gnu.
>
> Ok for 6.  For 7 we ask them to change it to the new builtins?

I'm investigating automatic conversion to HImode insn, something along
the lines:

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

But it looks that __builtin_clzs and __builtin_ctzs will also have to stay.

Uros.
diff mbox

Patch

Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 243649)
+++ config/i386/i386.c	(working copy)
@@ -32396,6 +32396,7 @@  enum ix86_builtins
 
   /* LZCNT */
   IX86_BUILTIN_LZCNT16,
+  IX86_BUILTIN_CLZS,
   IX86_BUILTIN_LZCNT32,
   IX86_BUILTIN_LZCNT64,
 
@@ -32422,6 +32423,7 @@  enum ix86_builtins
   IX86_BUILTIN_BEXTR32,
   IX86_BUILTIN_BEXTR64,
   IX86_BUILTIN_TZCNT16,
+  IX86_BUILTIN_CTZS,
   IX86_BUILTIN_TZCNT32,
   IX86_BUILTIN_TZCNT64,
 
@@ -33813,6 +33815,8 @@  static const struct builtin_description bdesc_args
 
   /* LZCNT */
   { 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.  */
+  { OPTION_MASK_ISA_LZCNT, CODE_FOR_lzcnt_hi, "__builtin_clzs", IX86_BUILTIN_CLZS, UNKNOWN, (int) UINT16_FTYPE_UINT16 },
   { OPTION_MASK_ISA_LZCNT, CODE_FOR_lzcnt_si, "__builtin_ia32_lzcnt_u32", IX86_BUILTIN_LZCNT32, UNKNOWN, (int) UINT_FTYPE_UINT },
   { OPTION_MASK_ISA_LZCNT | OPTION_MASK_ISA_64BIT, CODE_FOR_lzcnt_di, "__builtin_ia32_lzcnt_u64", IX86_BUILTIN_LZCNT64, UNKNOWN, (int) UINT64_FTYPE_UINT64 },
 
@@ -33821,6 +33825,8 @@  static const struct builtin_description bdesc_args
   { 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 },
 
   { 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.  */
+  { OPTION_MASK_ISA_BMI, CODE_FOR_bmi_tzcnt_hi, "__builtin_ctzs", IX86_BUILTIN_CTZS, UNKNOWN, (int) UINT16_FTYPE_UINT16 },
   { OPTION_MASK_ISA_BMI, CODE_FOR_bmi_tzcnt_si, "__builtin_ia32_tzcnt_u32", IX86_BUILTIN_TZCNT32, UNKNOWN, (int) UINT_FTYPE_UINT },
   { 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 },
 
@@ -37603,6 +37609,7 @@  ix86_fold_builtin (tree fndecl, int n_args,
           return fold_builtin_cpu (fndecl, args);
 
 	case IX86_BUILTIN_TZCNT16:
+	case IX86_BUILTIN_CTZS:
 	case IX86_BUILTIN_TZCNT32:
 	case IX86_BUILTIN_TZCNT64:
 	  gcc_assert (n_args == 1);
@@ -37610,7 +37617,8 @@  ix86_fold_builtin (tree fndecl, int n_args,
 	    {
 	      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)));
@@ -37620,6 +37628,7 @@  ix86_fold_builtin (tree fndecl, int n_args,
 	  break;
 
 	case IX86_BUILTIN_LZCNT16:
+	case IX86_BUILTIN_CLZS:
 	case IX86_BUILTIN_LZCNT32:
 	case IX86_BUILTIN_LZCNT64:
 	  gcc_assert (n_args == 1);
@@ -37627,7 +37636,8 @@  ix86_fold_builtin (tree fndecl, int n_args,
 	    {
 	      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)));