public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] using overflow_free_p to simplify pattern
@ 2023-09-19  5:23 Jiufu Guo
  2023-09-19  5:23 ` [PATCH 2/2] testcase: rename pr111303.c to pr111324.c Jiufu Guo
  2023-09-19 12:50 ` [PATCH 1/2] using overflow_free_p to simplify pattern Richard Biener
  0 siblings, 2 replies; 5+ messages in thread
From: Jiufu Guo @ 2023-09-19  5:23 UTC (permalink / raw)
  To: gcc-patches
  Cc: rguenther, jeffreyalaw, richard.sandiford, segher, dje.gcc,
	linkw, bergner, guojiufu, amacleod, aldyh

Hi,

In r14-3582, an "overflow_free_p" interface is added.
The pattern of "(t * 2) / 2" in match.pd can be simplified
by using this interface.

Bootstrap & regtest pass on ppc64{,le} and x86_64.
Is this ok for trunk?

BR,
Jeff (Jiufu)

gcc/ChangeLog:

	* match.pd ((t * 2) / 2): Update to use overflow_free_p.

---
 gcc/match.pd | 37 +++++++------------------------------
 1 file changed, 7 insertions(+), 30 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 87edf0e75c3..8bba7056000 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -926,36 +926,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
    (if (TYPE_OVERFLOW_UNDEFINED (type))
     @0
 #if GIMPLE
-    (with
-     {
-       bool overflowed = true;
-       value_range vr0, vr1;
-       if (INTEGRAL_TYPE_P (type)
-	   && get_range_query (cfun)->range_of_expr (vr0, @0)
-	   && get_range_query (cfun)->range_of_expr (vr1, @1)
-	   && !vr0.varying_p () && !vr0.undefined_p ()
-	   && !vr1.varying_p () && !vr1.undefined_p ())
-	 {
-	   wide_int wmin0 = vr0.lower_bound ();
-	   wide_int wmax0 = vr0.upper_bound ();
-	   wide_int wmin1 = vr1.lower_bound ();
-	   wide_int wmax1 = vr1.upper_bound ();
-	   /* If the multiplication can't overflow/wrap around, then
-	      it can be optimized too.  */
-	   wi::overflow_type min_ovf, max_ovf;
-	   wi::mul (wmin0, wmin1, TYPE_SIGN (type), &min_ovf);
-	   wi::mul (wmax0, wmax1, TYPE_SIGN (type), &max_ovf);
-	   if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE)
-	     {
-	       wi::mul (wmin0, wmax1, TYPE_SIGN (type), &min_ovf);
-	       wi::mul (wmax0, wmin1, TYPE_SIGN (type), &max_ovf);
-	       if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE)
-		 overflowed = false;
-	     }
-	 }
-     }
-    (if (!overflowed)
-     @0))
+    (with {value_range vr0, vr1;}
+     (if (INTEGRAL_TYPE_P (type)
+	  && get_range_query (cfun)->range_of_expr (vr0, @0)
+	  && get_range_query (cfun)->range_of_expr (vr1, @1)
+	  && !vr0.varying_p () && !vr1.varying_p ()
+	  && range_op_handler (MULT_EXPR).overflow_free_p (vr0, vr1))
+      @0))
 #endif
    ))))
 
-- 
2.25.1


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

* [PATCH 2/2] testcase: rename pr111303.c to pr111324.c
  2023-09-19  5:23 [PATCH 1/2] using overflow_free_p to simplify pattern Jiufu Guo
@ 2023-09-19  5:23 ` Jiufu Guo
  2023-09-19 12:51   ` Richard Biener
  2023-09-19 12:50 ` [PATCH 1/2] using overflow_free_p to simplify pattern Richard Biener
  1 sibling, 1 reply; 5+ messages in thread
From: Jiufu Guo @ 2023-09-19  5:23 UTC (permalink / raw)
  To: gcc-patches
  Cc: rguenther, jeffreyalaw, richard.sandiford, segher, dje.gcc,
	linkw, bergner, guojiufu, amacleod, aldyh

Hi,

When commit the fix for pr111324, the test cases was named as pr111303.c
by mistake.  Here, rename it to pr111324.c

Is this ok for trunk?

BR,
Jeff (Jiufu Guo)

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/pr111303.c: Rename to ...
	* gcc.dg/tree-ssa/pr111324.c: ... this.
---
 gcc/testsuite/gcc.dg/tree-ssa/{pr111303.c => pr111324.c} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename gcc/testsuite/gcc.dg/tree-ssa/{pr111303.c => pr111324.c} (100%)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr111303.c b/gcc/testsuite/gcc.dg/tree-ssa/pr111324.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/tree-ssa/pr111303.c
rename to gcc/testsuite/gcc.dg/tree-ssa/pr111324.c
-- 
2.25.1


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

* Re: [PATCH 1/2] using overflow_free_p to simplify pattern
  2023-09-19  5:23 [PATCH 1/2] using overflow_free_p to simplify pattern Jiufu Guo
  2023-09-19  5:23 ` [PATCH 2/2] testcase: rename pr111303.c to pr111324.c Jiufu Guo
@ 2023-09-19 12:50 ` Richard Biener
  2023-09-21  5:22   ` Jiufu Guo
  1 sibling, 1 reply; 5+ messages in thread
From: Richard Biener @ 2023-09-19 12:50 UTC (permalink / raw)
  To: Jiufu Guo
  Cc: gcc-patches, jeffreyalaw, richard.sandiford, segher, dje.gcc,
	linkw, bergner, amacleod, aldyh

On Tue, 19 Sep 2023, Jiufu Guo wrote:

> Hi,
> 
> In r14-3582, an "overflow_free_p" interface is added.
> The pattern of "(t * 2) / 2" in match.pd can be simplified
> by using this interface.
> 
> Bootstrap & regtest pass on ppc64{,le} and x86_64.
> Is this ok for trunk?
> 
> BR,
> Jeff (Jiufu)
> 
> gcc/ChangeLog:
> 
> 	* match.pd ((t * 2) / 2): Update to use overflow_free_p.
> 
> ---
>  gcc/match.pd | 37 +++++++------------------------------
>  1 file changed, 7 insertions(+), 30 deletions(-)
> 
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 87edf0e75c3..8bba7056000 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -926,36 +926,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>     (if (TYPE_OVERFLOW_UNDEFINED (type))
>      @0
>  #if GIMPLE
> -    (with
> -     {
> -       bool overflowed = true;
> -       value_range vr0, vr1;
> -       if (INTEGRAL_TYPE_P (type)
> -	   && get_range_query (cfun)->range_of_expr (vr0, @0)
> -	   && get_range_query (cfun)->range_of_expr (vr1, @1)
> -	   && !vr0.varying_p () && !vr0.undefined_p ()
> -	   && !vr1.varying_p () && !vr1.undefined_p ())
> -	 {
> -	   wide_int wmin0 = vr0.lower_bound ();
> -	   wide_int wmax0 = vr0.upper_bound ();
> -	   wide_int wmin1 = vr1.lower_bound ();
> -	   wide_int wmax1 = vr1.upper_bound ();
> -	   /* If the multiplication can't overflow/wrap around, then
> -	      it can be optimized too.  */
> -	   wi::overflow_type min_ovf, max_ovf;
> -	   wi::mul (wmin0, wmin1, TYPE_SIGN (type), &min_ovf);
> -	   wi::mul (wmax0, wmax1, TYPE_SIGN (type), &max_ovf);
> -	   if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE)
> -	     {
> -	       wi::mul (wmin0, wmax1, TYPE_SIGN (type), &min_ovf);
> -	       wi::mul (wmax0, wmin1, TYPE_SIGN (type), &max_ovf);
> -	       if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE)
> -		 overflowed = false;
> -	     }
> -	 }
> -     }
> -    (if (!overflowed)
> -     @0))
> +    (with {value_range vr0, vr1;}
> +     (if (INTEGRAL_TYPE_P (type)
> +	  && get_range_query (cfun)->range_of_expr (vr0, @0)
> +	  && get_range_query (cfun)->range_of_expr (vr1, @1)
> +	  && !vr0.varying_p () && !vr1.varying_p ()

From your other uses checking !varying_p doesn't seem necessary?

OK with omitting.

Richard.

> +	  && range_op_handler (MULT_EXPR).overflow_free_p (vr0, vr1))
> +      @0))
>  #endif
>     ))))
>  
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

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

* Re: [PATCH 2/2] testcase: rename pr111303.c to pr111324.c
  2023-09-19  5:23 ` [PATCH 2/2] testcase: rename pr111303.c to pr111324.c Jiufu Guo
@ 2023-09-19 12:51   ` Richard Biener
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Biener @ 2023-09-19 12:51 UTC (permalink / raw)
  To: Jiufu Guo
  Cc: gcc-patches, jeffreyalaw, richard.sandiford, segher, dje.gcc,
	linkw, bergner, amacleod, aldyh

On Tue, 19 Sep 2023, Jiufu Guo wrote:

> Hi,
> 
> When commit the fix for pr111324, the test cases was named as pr111303.c
> by mistake.  Here, rename it to pr111324.c
> 
> Is this ok for trunk?

OK.

> BR,
> Jeff (Jiufu Guo)
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.dg/tree-ssa/pr111303.c: Rename to ...
> 	* gcc.dg/tree-ssa/pr111324.c: ... this.
> ---
>  gcc/testsuite/gcc.dg/tree-ssa/{pr111303.c => pr111324.c} | 0
>  1 file changed, 0 insertions(+), 0 deletions(-)
>  rename gcc/testsuite/gcc.dg/tree-ssa/{pr111303.c => pr111324.c} (100%)
> 
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr111303.c b/gcc/testsuite/gcc.dg/tree-ssa/pr111324.c
> similarity index 100%
> rename from gcc/testsuite/gcc.dg/tree-ssa/pr111303.c
> rename to gcc/testsuite/gcc.dg/tree-ssa/pr111324.c
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

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

* Re: [PATCH 1/2] using overflow_free_p to simplify pattern
  2023-09-19 12:50 ` [PATCH 1/2] using overflow_free_p to simplify pattern Richard Biener
@ 2023-09-21  5:22   ` Jiufu Guo
  0 siblings, 0 replies; 5+ messages in thread
From: Jiufu Guo @ 2023-09-21  5:22 UTC (permalink / raw)
  To: Richard Biener
  Cc: gcc-patches, jeffreyalaw, richard.sandiford, segher, dje.gcc,
	linkw, bergner, amacleod, aldyh


Hi,

Richard Biener <rguenther@suse.de> writes:

> On Tue, 19 Sep 2023, Jiufu Guo wrote:
>
>> Hi,
>> 
>> In r14-3582, an "overflow_free_p" interface is added.
>> The pattern of "(t * 2) / 2" in match.pd can be simplified
>> by using this interface.
>> 
>> Bootstrap & regtest pass on ppc64{,le} and x86_64.
>> Is this ok for trunk?
>> 
>> BR,
>> Jeff (Jiufu)
>> 
>> gcc/ChangeLog:
>> 
>> 	* match.pd ((t * 2) / 2): Update to use overflow_free_p.
>> 
>> ---
>>  gcc/match.pd | 37 +++++++------------------------------
>>  1 file changed, 7 insertions(+), 30 deletions(-)
>> 
>> diff --git a/gcc/match.pd b/gcc/match.pd
>> index 87edf0e75c3..8bba7056000 100644
>> --- a/gcc/match.pd
>> +++ b/gcc/match.pd
>> @@ -926,36 +926,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>>     (if (TYPE_OVERFLOW_UNDEFINED (type))
>>      @0
>>  #if GIMPLE
>> -    (with
>> -     {
>> -       bool overflowed = true;
>> -       value_range vr0, vr1;
>> -       if (INTEGRAL_TYPE_P (type)
>> -	   && get_range_query (cfun)->range_of_expr (vr0, @0)
>> -	   && get_range_query (cfun)->range_of_expr (vr1, @1)
>> -	   && !vr0.varying_p () && !vr0.undefined_p ()
>> -	   && !vr1.varying_p () && !vr1.undefined_p ())
>> -	 {
>> -	   wide_int wmin0 = vr0.lower_bound ();
>> -	   wide_int wmax0 = vr0.upper_bound ();
>> -	   wide_int wmin1 = vr1.lower_bound ();
>> -	   wide_int wmax1 = vr1.upper_bound ();
>> -	   /* If the multiplication can't overflow/wrap around, then
>> -	      it can be optimized too.  */
>> -	   wi::overflow_type min_ovf, max_ovf;
>> -	   wi::mul (wmin0, wmin1, TYPE_SIGN (type), &min_ovf);
>> -	   wi::mul (wmax0, wmax1, TYPE_SIGN (type), &max_ovf);
>> -	   if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE)
>> -	     {
>> -	       wi::mul (wmin0, wmax1, TYPE_SIGN (type), &min_ovf);
>> -	       wi::mul (wmax0, wmin1, TYPE_SIGN (type), &max_ovf);
>> -	       if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE)
>> -		 overflowed = false;
>> -	     }
>> -	 }
>> -     }
>> -    (if (!overflowed)
>> -     @0))
>> +    (with {value_range vr0, vr1;}
>> +     (if (INTEGRAL_TYPE_P (type)
>> +	  && get_range_query (cfun)->range_of_expr (vr0, @0)
>> +	  && get_range_query (cfun)->range_of_expr (vr1, @1)
>> +	  && !vr0.varying_p () && !vr1.varying_p ()
>
> From your other uses checking !varying_p doesn't seem necessary?

Thanks for pointing out this!!
Yes, !varying_p is not needed, overflow_free_p could cover it.

Committed via r14-4191.

BR,
Jeff (Jiufu Guo)

>
> OK with omitting.
>
> Richard.
>
>> +	  && range_op_handler (MULT_EXPR).overflow_free_p (vr0, vr1))
>> +      @0))
>>  #endif
>>     ))))
>>  
>> 

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

end of thread, other threads:[~2023-09-21  5:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-19  5:23 [PATCH 1/2] using overflow_free_p to simplify pattern Jiufu Guo
2023-09-19  5:23 ` [PATCH 2/2] testcase: rename pr111303.c to pr111324.c Jiufu Guo
2023-09-19 12:51   ` Richard Biener
2023-09-19 12:50 ` [PATCH 1/2] using overflow_free_p to simplify pattern Richard Biener
2023-09-21  5:22   ` Jiufu Guo

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