public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] match.pd: Further complex simplification fixes [PR104675]
@ 2022-02-25 17:58 Jakub Jelinek
  2022-02-25 19:05 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2022-02-25 17:58 UTC (permalink / raw)
  To: Richard Biener, Marc Glisse; +Cc: gcc-patches

Hi!

Mark mentioned in the PR further 2 simplifications that also ICE
with complex types.
For these, eventually (but IMO GCC 13 materials) we could support it
for vector types if it would be uniform vector constants.
Currently integer_pow2p is true only for INTEGER_CSTs and COMPLEX_CSTs
and we can't use bit_and etc. for complex type.

Bootstrapped/regtested on powerpc64le-linux and powerpc64-linux, ok
for trunk?

2022-02-25  Jakub Jelinek  <jakub@redhat.com>
	    Marc Glisse  <marc.glisse@inria.fr>

	PR tree-optimization/104675
	* match.pd (t * 2U / 2 -> t & (~0 / 2), t / 2U * 2 -> t & ~1):
	Restrict simplifications to INTEGRAL_TYPE_P.

	* gcc.dg/pr104675-3.c : New test.

--- gcc/match.pd.jj	2022-02-25 10:55:08.000000000 +0100
+++ gcc/match.pd	2022-02-25 11:48:04.730110154 +0100
@@ -731,7 +731,7 @@ (define_operator_list SYNC_FETCH_AND_AND
 /* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF.  */
 (simplify
  (trunc_div (mult @0 integer_pow2p@1) @1)
- (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && TYPE_UNSIGNED (TREE_TYPE (@0)))
   (bit_and @0 { wide_int_to_tree
 		(type, wi::mask (TYPE_PRECISION (type)
 				 - wi::exact_log2 (wi::to_wide (@1)),
@@ -740,7 +740,7 @@ (define_operator_list SYNC_FETCH_AND_AND
 /* Simplify (unsigned t / 2) * 2 -> unsigned t & ~1.  */
 (simplify
  (mult (trunc_div @0 integer_pow2p@1) @1)
- (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && TYPE_UNSIGNED (TREE_TYPE (@0)))
   (bit_and @0 (negate @1))))
 
 /* Simplify (t * 2) / 2) -> t.  */
--- gcc/testsuite/gcc.dg/pr104675-3.c.jj	2022-02-25 11:24:43.111619659 +0100
+++ gcc/testsuite/gcc.dg/pr104675-3.c	2022-02-25 11:26:35.406056600 +0100
@@ -0,0 +1,29 @@
+/* PR tree-optimization/104675 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+_Complex unsigned int
+foo (_Complex unsigned int x)
+{
+  return (x / 2) * 2;
+}
+
+_Complex unsigned int
+bar (_Complex unsigned int x)
+{
+  return (x * 2) / 2;
+}
+
+_Complex unsigned int
+baz (_Complex unsigned int x)
+{
+  _Complex unsigned int y = x / 2;
+  return y * 2;
+}
+
+_Complex unsigned int
+qux (_Complex unsigned int x)
+{
+  _Complex unsigned int y = x * 2;
+  return y / 2;
+}

	Jakub


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

* Re: [PATCH] match.pd: Further complex simplification fixes [PR104675]
  2022-02-25 17:58 [PATCH] match.pd: Further complex simplification fixes [PR104675] Jakub Jelinek
@ 2022-02-25 19:05 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-02-25 19:05 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Marc Glisse, gcc-patches



> Am 25.02.2022 um 18:58 schrieb Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org>:
> 
> Hi!
> 
> Mark mentioned in the PR further 2 simplifications that also ICE
> with complex types.
> For these, eventually (but IMO GCC 13 materials) we could support it
> for vector types if it would be uniform vector constants.
> Currently integer_pow2p is true only for INTEGER_CSTs and COMPLEX_CSTs
> and we can't use bit_and etc. for complex type.
> 
> Bootstrapped/regtested on powerpc64le-linux and powerpc64-linux, ok
> for trunk?

Ok.

Richard 

> 2022-02-25  Jakub Jelinek  <jakub@redhat.com>
>        Marc Glisse  <marc.glisse@inria.fr>
> 
>    PR tree-optimization/104675
>    * match.pd (t * 2U / 2 -> t & (~0 / 2), t / 2U * 2 -> t & ~1):
>    Restrict simplifications to INTEGRAL_TYPE_P.
> 
>    * gcc.dg/pr104675-3.c : New test.
> 
> --- gcc/match.pd.jj    2022-02-25 10:55:08.000000000 +0100
> +++ gcc/match.pd    2022-02-25 11:48:04.730110154 +0100
> @@ -731,7 +731,7 @@ (define_operator_list SYNC_FETCH_AND_AND
> /* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF.  */
> (simplify
>  (trunc_div (mult @0 integer_pow2p@1) @1)
> - (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
> + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && TYPE_UNSIGNED (TREE_TYPE (@0)))
>   (bit_and @0 { wide_int_to_tree
>        (type, wi::mask (TYPE_PRECISION (type)
>                 - wi::exact_log2 (wi::to_wide (@1)),
> @@ -740,7 +740,7 @@ (define_operator_list SYNC_FETCH_AND_AND
> /* Simplify (unsigned t / 2) * 2 -> unsigned t & ~1.  */
> (simplify
>  (mult (trunc_div @0 integer_pow2p@1) @1)
> - (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
> + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && TYPE_UNSIGNED (TREE_TYPE (@0)))
>   (bit_and @0 (negate @1))))
> 
> /* Simplify (t * 2) / 2) -> t.  */
> --- gcc/testsuite/gcc.dg/pr104675-3.c.jj    2022-02-25 11:24:43.111619659 +0100
> +++ gcc/testsuite/gcc.dg/pr104675-3.c    2022-02-25 11:26:35.406056600 +0100
> @@ -0,0 +1,29 @@
> +/* PR tree-optimization/104675 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2" } */
> +
> +_Complex unsigned int
> +foo (_Complex unsigned int x)
> +{
> +  return (x / 2) * 2;
> +}
> +
> +_Complex unsigned int
> +bar (_Complex unsigned int x)
> +{
> +  return (x * 2) / 2;
> +}
> +
> +_Complex unsigned int
> +baz (_Complex unsigned int x)
> +{
> +  _Complex unsigned int y = x / 2;
> +  return y * 2;
> +}
> +
> +_Complex unsigned int
> +qux (_Complex unsigned int x)
> +{
> +  _Complex unsigned int y = x * 2;
> +  return y / 2;
> +}
> 
>    Jakub
> 

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

end of thread, other threads:[~2022-02-25 19:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-25 17:58 [PATCH] match.pd: Further complex simplification fixes [PR104675] Jakub Jelinek
2022-02-25 19:05 ` 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).