public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-vect-patterns: One small vect_recog_ctz_ffs_pattern tweak [PR109011]
@ 2023-04-20 17:38 Jakub Jelinek
  2023-04-20 17:41 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2023-04-20 17:38 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

I've noticed I've made a typo, ifn in this function this late
is always only IFN_CTZ or IFN_FFS, never IFN_CLZ.

Due to this typo, we weren't using the originally intended
.CTZ (X) = .POPCOUNT ((X - 1) & ~X)
but
.CTZ (X) = PREC - .POPCOUNT (X | -X)
instead when we want to emit __builtin_ctz*/.CTZ using .POPCOUNT.
Both compute the same value, both are defined at 0 with the
same value (PREC), both have same number of GIMPLE statements,
but I think the former ought to be preferred, because lots of targets
have andn as a single operation rather than two, and also putting
a -1 constant into a vector register is often cheaper than vector
with broadcast PREC power of two value.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-04-20  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/109011
	* tree-vect-patterns.cc (vect_recog_ctz_ffs_pattern): Use
	.CTZ (X) = .POPCOUNT ((X - 1) & ~X) in preference to
	.CTZ (X) = PREC - .POPCOUNT (X | -X).

--- gcc/tree-vect-patterns.cc.jj	2023-04-20 11:55:03.576154120 +0200
+++ gcc/tree-vect-patterns.cc	2023-04-20 12:09:17.884633795 +0200
@@ -1630,7 +1630,7 @@ vect_recog_ctz_ffs_pattern (vec_info *vi
        && defined_at_zero_new
        && val == prec
        && val_new == prec)
-      || (ifnnew == IFN_POPCOUNT && ifn == IFN_CLZ))
+      || (ifnnew == IFN_POPCOUNT && ifn == IFN_CTZ))
     {
       /* .CTZ (X) = PREC - .CLZ ((X - 1) & ~X)
 	 .CTZ (X) = .POPCOUNT ((X - 1) & ~X).  */

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] tree-vect-patterns: One small vect_recog_ctz_ffs_pattern tweak [PR109011]
  2023-04-20 17:38 [PATCH] tree-vect-patterns: One small vect_recog_ctz_ffs_pattern tweak [PR109011] Jakub Jelinek
@ 2023-04-20 17:41 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-04-20 17:41 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Richard Biener, gcc-patches



> Am 20.04.2023 um 19:40 schrieb Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org>:
> 
> Hi!
> 
> I've noticed I've made a typo, ifn in this function this late
> is always only IFN_CTZ or IFN_FFS, never IFN_CLZ.
> 
> Due to this typo, we weren't using the originally intended
> .CTZ (X) = .POPCOUNT ((X - 1) & ~X)
> but
> .CTZ (X) = PREC - .POPCOUNT (X | -X)
> instead when we want to emit __builtin_ctz*/.CTZ using .POPCOUNT.
> Both compute the same value, both are defined at 0 with the
> same value (PREC), both have same number of GIMPLE statements,
> but I think the former ought to be preferred, because lots of targets
> have andn as a single operation rather than two, and also putting
> a -1 constant into a vector register is often cheaper than vector
> with broadcast PREC power of two value.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok

> 2023-04-20  Jakub Jelinek  <jakub@redhat.com>
> 
>    PR tree-optimization/109011
>    * tree-vect-patterns.cc (vect_recog_ctz_ffs_pattern): Use
>    .CTZ (X) = .POPCOUNT ((X - 1) & ~X) in preference to
>    .CTZ (X) = PREC - .POPCOUNT (X | -X).
> 
> --- gcc/tree-vect-patterns.cc.jj    2023-04-20 11:55:03.576154120 +0200
> +++ gcc/tree-vect-patterns.cc    2023-04-20 12:09:17.884633795 +0200
> @@ -1630,7 +1630,7 @@ vect_recog_ctz_ffs_pattern (vec_info *vi
>        && defined_at_zero_new
>        && val == prec
>        && val_new == prec)
> -      || (ifnnew == IFN_POPCOUNT && ifn == IFN_CLZ))
> +      || (ifnnew == IFN_POPCOUNT && ifn == IFN_CTZ))
>     {
>       /* .CTZ (X) = PREC - .CLZ ((X - 1) & ~X)
>     .CTZ (X) = .POPCOUNT ((X - 1) & ~X).  */
> 
>    Jakub
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-20 17:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-20 17:38 [PATCH] tree-vect-patterns: One small vect_recog_ctz_ffs_pattern tweak [PR109011] Jakub Jelinek
2023-04-20 17:41 ` Richard Biener

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