public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] MATCH: Add ABSU<a> == 0 to a == 0 simplification
@ 2023-05-04 23:40 Andrew Pinski
  2023-05-05  5:19 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Pinski @ 2023-05-04 23:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew Pinski

There is already an `ABS<a> == 0` to `a == 0` pattern,
this just extends that to ABSU too.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

	PR tree-optimization/109722

gcc/ChangeLog:

	* match.pd: Extend the `ABS<a> == 0` pattern
	to cover `ABSU<a> == 0` too.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/abs-1.c: New test.
---
 gcc/match.pd                          | 11 ++++++-----
 gcc/testsuite/gcc.dg/tree-ssa/abs-1.c | 12 ++++++++++++
 2 files changed, 18 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/abs-1.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 08a4f8ebdc1..ceae1c34abc 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -5807,11 +5807,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
     (if (tem && !TREE_OVERFLOW (tem))
      (scmp @0 { tem; }))))))
 
-/* Convert ABS_EXPR<x> == 0 or ABS_EXPR<x> != 0 to x == 0 or x != 0.  */
-(for op (eq ne)
- (simplify
-  (op (abs @0) zerop@1)
-  (op @0 @1)))
+/* Convert ABS[U]_EXPR<x> == 0 or ABS[U]_EXPR<x> != 0 to x == 0 or x != 0.  */
+(for op (abs absu)
+ (for eqne (eq ne)
+  (simplify
+   (eqne (op @0) zerop@1)
+   (eqne @0 { build_zero_cst (TREE_TYPE (@0)); }))))
 
 /* From fold_sign_changed_comparison and fold_widened_comparison.
    FIXME: the lack of symmetry is disturbing.  */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/abs-1.c b/gcc/testsuite/gcc.dg/tree-ssa/abs-1.c
new file mode 100644
index 00000000000..ce404111103
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/abs-1.c
@@ -0,0 +1,12 @@
+/* PR tree-optimization/109722 */
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-gimple -fdump-tree-optimized" } */
+
+int g(signed char x){
+    x = x < 0 ? -x : x;
+    return x == 0;
+}
+
+/* This should work even if int is 16bits. */
+/* { dg-final { scan-tree-dump "ABSU_EXPR" "gimple"} } */
+/* { dg-final { scan-tree-dump-not "ABSU_EXPR" "optimized"} } */
-- 
2.31.1


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

* Re: [PATCH] MATCH: Add ABSU<a> == 0 to a == 0 simplification
  2023-05-04 23:40 [PATCH] MATCH: Add ABSU<a> == 0 to a == 0 simplification Andrew Pinski
@ 2023-05-05  5:19 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-05-05  5:19 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-patches



> Am 05.05.2023 um 01:41 schrieb Andrew Pinski via Gcc-patches <gcc-patches@gcc.gnu.org>:
> 
> There is already an `ABS<a> == 0` to `a == 0` pattern,
> this just extends that to ABSU too.
> 
> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Ok

Richard 

>    PR tree-optimization/109722
> 
> gcc/ChangeLog:
> 
>    * match.pd: Extend the `ABS<a> == 0` pattern
>    to cover `ABSU<a> == 0` too.
> 
> gcc/testsuite/ChangeLog:
> 
>    * gcc.dg/tree-ssa/abs-1.c: New test.
> ---
> gcc/match.pd                          | 11 ++++++-----
> gcc/testsuite/gcc.dg/tree-ssa/abs-1.c | 12 ++++++++++++
> 2 files changed, 18 insertions(+), 5 deletions(-)
> create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/abs-1.c
> 
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 08a4f8ebdc1..ceae1c34abc 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -5807,11 +5807,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>     (if (tem && !TREE_OVERFLOW (tem))
>      (scmp @0 { tem; }))))))
> 
> -/* Convert ABS_EXPR<x> == 0 or ABS_EXPR<x> != 0 to x == 0 or x != 0.  */
> -(for op (eq ne)
> - (simplify
> -  (op (abs @0) zerop@1)
> -  (op @0 @1)))
> +/* Convert ABS[U]_EXPR<x> == 0 or ABS[U]_EXPR<x> != 0 to x == 0 or x != 0.  */
> +(for op (abs absu)
> + (for eqne (eq ne)
> +  (simplify
> +   (eqne (op @0) zerop@1)
> +   (eqne @0 { build_zero_cst (TREE_TYPE (@0)); }))))
> 
> /* From fold_sign_changed_comparison and fold_widened_comparison.
>    FIXME: the lack of symmetry is disturbing.  */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/abs-1.c b/gcc/testsuite/gcc.dg/tree-ssa/abs-1.c
> new file mode 100644
> index 00000000000..ce404111103
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/abs-1.c
> @@ -0,0 +1,12 @@
> +/* PR tree-optimization/109722 */
> +/* { dg-do compile } */
> +/* { dg-options "-O -fdump-tree-gimple -fdump-tree-optimized" } */
> +
> +int g(signed char x){
> +    x = x < 0 ? -x : x;
> +    return x == 0;
> +}
> +
> +/* This should work even if int is 16bits. */
> +/* { dg-final { scan-tree-dump "ABSU_EXPR" "gimple"} } */
> +/* { dg-final { scan-tree-dump-not "ABSU_EXPR" "optimized"} } */
> -- 
> 2.31.1
> 

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

end of thread, other threads:[~2023-05-05  5:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-04 23:40 [PATCH] MATCH: Add ABSU<a> == 0 to a == 0 simplification Andrew Pinski
2023-05-05  5:19 ` 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).