* [PATCH] tree-optimization/110278 - uns < (typeof uns)(uns != 0) is always false
@ 2023-06-16 11:45 Richard Biener
2023-06-16 23:14 ` Andrew Pinski
0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2023-06-16 11:45 UTC (permalink / raw)
To: gcc-patches
The following adds two patterns simplifying comparisons,
uns < (typeof uns)(uns != 0) is always false and x != (typeof x)(x == 0)
is always true.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR tree-optimization/110278
* match.pd (uns < (typeof uns)(uns != 0) -> false): New.
(x != (typeof x)(x == 0) -> true): Likewise.
---
gcc/match.pd | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/gcc/match.pd b/gcc/match.pd
index 264f9cb8a40..48b76e6a051 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6410,6 +6410,17 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (cmp == GT_EXPR)
(lt (view_convert:st @0) { build_zero_cst (st); })))))))))))
+/* unsigned < (typeof unsigned)(unsigned != 0) is always false. */
+(simplify
+ (lt:c @0 (convert (ne @0 integer_zerop)))
+ (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+ { constant_boolean_node (false, type); }))
+
+/* x != (typeof x)(x == 0) is always true. */
+(simplify
+ (ne:c @0 (convert (eq @0 integer_zerop)))
+ { constant_boolean_node (true, type); })
+
(for cmp (unordered ordered unlt unle ungt unge uneq ltgt)
/* If the second operand is NaN, the result is constant. */
(simplify
--
2.35.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tree-optimization/110278 - uns < (typeof uns)(uns != 0) is always false
2023-06-16 11:45 [PATCH] tree-optimization/110278 - uns < (typeof uns)(uns != 0) is always false Richard Biener
@ 2023-06-16 23:14 ` Andrew Pinski
2023-06-16 23:23 ` Andrew Pinski
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Pinski @ 2023-06-16 23:14 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
On Fri, Jun 16, 2023 at 4:46 AM Richard Biener via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> The following adds two patterns simplifying comparisons,
> uns < (typeof uns)(uns != 0) is always false and x != (typeof x)(x == 0)
> is always true.
A few more that should be done (I will file a bug in a few minutes):
`x == (typeof x)(x == 0)` is always false.
`x == (typeof x)(x != 0)` is `(unsigned_type)x <= 1`
`x != (typeof x)(x != 0)` is `(unsigned_type)x > 1`
`uns <= (typeof uns)(uns != 0)` -> `uns <= 1`
`uns > (typeof uns)(uns != 0)` is `uns > 1`
`uns >= (typeof uns)(uns != 0)` is always true
That should be all of them I think and I think I did it correctly.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
>
> PR tree-optimization/110278
> * match.pd (uns < (typeof uns)(uns != 0) -> false): New.
> (x != (typeof x)(x == 0) -> true): Likewise.
> ---
> gcc/match.pd | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 264f9cb8a40..48b76e6a051 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -6410,6 +6410,17 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> (if (cmp == GT_EXPR)
> (lt (view_convert:st @0) { build_zero_cst (st); })))))))))))
>
> +/* unsigned < (typeof unsigned)(unsigned != 0) is always false. */
> +(simplify
> + (lt:c @0 (convert (ne @0 integer_zerop)))
> + (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
> + { constant_boolean_node (false, type); }))
> +
> +/* x != (typeof x)(x == 0) is always true. */
> +(simplify
> + (ne:c @0 (convert (eq @0 integer_zerop)))
> + { constant_boolean_node (true, type); })
> +
> (for cmp (unordered ordered unlt unle ungt unge uneq ltgt)
> /* If the second operand is NaN, the result is constant. */
> (simplify
> --
> 2.35.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tree-optimization/110278 - uns < (typeof uns)(uns != 0) is always false
2023-06-16 23:14 ` Andrew Pinski
@ 2023-06-16 23:23 ` Andrew Pinski
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Pinski @ 2023-06-16 23:23 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
On Fri, Jun 16, 2023 at 4:14 PM Andrew Pinski <pinskia@gmail.com> wrote:
>
> On Fri, Jun 16, 2023 at 4:46 AM Richard Biener via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > The following adds two patterns simplifying comparisons,
> > uns < (typeof uns)(uns != 0) is always false and x != (typeof x)(x == 0)
> > is always true.
>
> A few more that should be done (I will file a bug in a few minutes):
> `x == (typeof x)(x == 0)` is always false.
> `x == (typeof x)(x != 0)` is `(unsigned_type)x <= 1`
> `x != (typeof x)(x != 0)` is `(unsigned_type)x > 1`
> `uns <= (typeof uns)(uns != 0)` -> `uns <= 1`
> `uns > (typeof uns)(uns != 0)` is `uns > 1`
> `uns >= (typeof uns)(uns != 0)` is always true
>
> That should be all of them I think and I think I did it correctly.
Filed as PR 110293 .
Thanks,
Andrew
>
> >
> > Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
> >
> > PR tree-optimization/110278
> > * match.pd (uns < (typeof uns)(uns != 0) -> false): New.
> > (x != (typeof x)(x == 0) -> true): Likewise.
> > ---
> > gcc/match.pd | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/gcc/match.pd b/gcc/match.pd
> > index 264f9cb8a40..48b76e6a051 100644
> > --- a/gcc/match.pd
> > +++ b/gcc/match.pd
> > @@ -6410,6 +6410,17 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> > (if (cmp == GT_EXPR)
> > (lt (view_convert:st @0) { build_zero_cst (st); })))))))))))
> >
> > +/* unsigned < (typeof unsigned)(unsigned != 0) is always false. */
> > +(simplify
> > + (lt:c @0 (convert (ne @0 integer_zerop)))
> > + (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
> > + { constant_boolean_node (false, type); }))
> > +
> > +/* x != (typeof x)(x == 0) is always true. */
> > +(simplify
> > + (ne:c @0 (convert (eq @0 integer_zerop)))
> > + { constant_boolean_node (true, type); })
> > +
> > (for cmp (unordered ordered unlt unle ungt unge uneq ltgt)
> > /* If the second operand is NaN, the result is constant. */
> > (simplify
> > --
> > 2.35.3
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-16 23:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-16 11:45 [PATCH] tree-optimization/110278 - uns < (typeof uns)(uns != 0) is always false Richard Biener
2023-06-16 23:14 ` Andrew Pinski
2023-06-16 23:23 ` 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).