* [PATCH] MATCH: Port CLRSB part of builtin_zero_pattern
@ 2023-04-30 21:12 Andrew Pinski
2023-05-02 12:21 ` Richard Biener
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Pinski @ 2023-04-30 21:12 UTC (permalink / raw)
To: gcc-patches; +Cc: Andrew Pinski
This ports the clrsb builtin part of builtin_zero_pattern
to match.pd. A simple pattern to port.
OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
gcc/ChangeLog:
* match.pd (a != 0 ? CLRSB(a) : CST -> CLRSB(a)): New
pattern.
---
gcc/match.pd | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/gcc/match.pd b/gcc/match.pd
index 0e782cde71d..bf918ba70ce 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -7787,6 +7787,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(cond (ne @0 integer_zerop@1) (func@4 (convert? @2)) integer_zerop@3)
@4))
+/* a != 0 ? FUN(a) : CST -> Fun(a) for some CLRSB builtins
+ where CST is precision-1. */
+(for func (CLRSB)
+ (simplify
+ (cond (ne @0 integer_zerop@1) (func@5 (convert?@4 @2)) INTEGER_CST@3)
+ (if (wi::to_widest (@3) == TYPE_PRECISION (TREE_TYPE (@4)) - 1)
+ @5)))
+
#if GIMPLE
/* a != 0 ? CLZ(a) : CST -> .CLZ(a) where CST is the result of the internal function for 0. */
(for func (CLZ)
--
2.31.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] MATCH: Port CLRSB part of builtin_zero_pattern
2023-04-30 21:12 [PATCH] MATCH: Port CLRSB part of builtin_zero_pattern Andrew Pinski
@ 2023-05-02 12:21 ` Richard Biener
2023-05-02 21:49 ` Andrew Pinski
0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2023-05-02 12:21 UTC (permalink / raw)
To: Andrew Pinski; +Cc: gcc-patches
On Sun, Apr 30, 2023 at 11:13 PM Andrew Pinski via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> This ports the clrsb builtin part of builtin_zero_pattern
> to match.pd. A simple pattern to port.
>
> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
>
> gcc/ChangeLog:
>
> * match.pd (a != 0 ? CLRSB(a) : CST -> CLRSB(a)): New
> pattern.
> ---
> gcc/match.pd | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 0e782cde71d..bf918ba70ce 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -7787,6 +7787,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> (cond (ne @0 integer_zerop@1) (func@4 (convert? @2)) integer_zerop@3)
> @4))
>
> +/* a != 0 ? FUN(a) : CST -> Fun(a) for some CLRSB builtins
> + where CST is precision-1. */
> +(for func (CLRSB)
> + (simplify
> + (cond (ne @0 integer_zerop@1) (func@5 (convert?@4 @2)) INTEGER_CST@3)
As you don't seem to use @2 why not match (func@5 @4) only?
Otherwise LGTM.
> + (if (wi::to_widest (@3) == TYPE_PRECISION (TREE_TYPE (@4)) - 1)
> + @5)))
> +
> #if GIMPLE
> /* a != 0 ? CLZ(a) : CST -> .CLZ(a) where CST is the result of the internal function for 0. */
> (for func (CLZ)
> --
> 2.31.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] MATCH: Port CLRSB part of builtin_zero_pattern
2023-05-02 12:21 ` Richard Biener
@ 2023-05-02 21:49 ` Andrew Pinski
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Pinski @ 2023-05-02 21:49 UTC (permalink / raw)
To: Richard Biener; +Cc: Andrew Pinski, gcc-patches
On Tue, May 2, 2023 at 5:24 AM Richard Biener via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On Sun, Apr 30, 2023 at 11:13 PM Andrew Pinski via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > This ports the clrsb builtin part of builtin_zero_pattern
> > to match.pd. A simple pattern to port.
> >
> > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
> >
> > gcc/ChangeLog:
> >
> > * match.pd (a != 0 ? CLRSB(a) : CST -> CLRSB(a)): New
> > pattern.
> > ---
> > gcc/match.pd | 8 ++++++++
> > 1 file changed, 8 insertions(+)
> >
> > diff --git a/gcc/match.pd b/gcc/match.pd
> > index 0e782cde71d..bf918ba70ce 100644
> > --- a/gcc/match.pd
> > +++ b/gcc/match.pd
> > @@ -7787,6 +7787,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> > (cond (ne @0 integer_zerop@1) (func@4 (convert? @2)) integer_zerop@3)
> > @4))
> >
> > +/* a != 0 ? FUN(a) : CST -> Fun(a) for some CLRSB builtins
> > + where CST is precision-1. */
> > +(for func (CLRSB)
> > + (simplify
> > + (cond (ne @0 integer_zerop@1) (func@5 (convert?@4 @2)) INTEGER_CST@3)
>
> As you don't seem to use @2 why not match (func@5 @4) only?
Thanks for catching this, @2 should really have been @0, otherwise we
get the wrong answer in general.
I fixed the other patterns I just added for this same issue too.
This is what I committed instead:
/* a != 0 ? FUN(a) : CST -> Fun(a) for some CLRSB builtins
where CST is precision-1. */
(for func (CLRSB)
(simplify
(cond (ne @0 integer_zerop@1) (func@4 (convert?@3 @0)) INTEGER_CST@2)
(if (wi::to_widest (@2) == TYPE_PRECISION (TREE_TYPE (@3)) - 1)
@4)))
Thanks,
Andrew
>
> Otherwise LGTM.
>
> > + (if (wi::to_widest (@3) == TYPE_PRECISION (TREE_TYPE (@4)) - 1)
> > + @5)))
> > +
> > #if GIMPLE
> > /* a != 0 ? CLZ(a) : CST -> .CLZ(a) where CST is the result of the internal function for 0. */
> > (for func (CLZ)
> > --
> > 2.31.1
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-02 21:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-30 21:12 [PATCH] MATCH: Port CLRSB part of builtin_zero_pattern Andrew Pinski
2023-05-02 12:21 ` Richard Biener
2023-05-02 21:49 ` Andrew Pinski
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).