diff mbox series

middle-end/103193 - avoid canonicalizing <= and >= to == for floats

Message ID 5sn852o1-o6r4-17p-38s4-ps272q2q459r@fhfr.qr
State New
Headers show
Series middle-end/103193 - avoid canonicalizing <= and >= to == for floats | expand

Commit Message

Richard Biener Nov. 15, 2021, 11:16 a.m. UTC
This avoids doing aforementioned canoncalization when -ftrapping-math
is in effect and we honor NaNs.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

OK?

Thanks,
Richard.

2021-11-15  Richard Biener  <rguenther@suse.de>

	PR middle-end/103193
	* match.pd: Avoid canonicalizing (le/ge @0 @0) to (eq @0 @0)
	with NaNs and -ftrapping-math.
---
 gcc/match.pd | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Richard Biener Nov. 24, 2021, 9 a.m. UTC | #1
On Mon, Nov 15, 2021 at 12:16 PM Richard Biener via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> This avoids doing aforementioned canoncalization when -ftrapping-math
> is in effect and we honor NaNs.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
>
> OK?

Ping.

>
> Thanks,
> Richard.
>
> 2021-11-15  Richard Biener  <rguenther@suse.de>
>
>         PR middle-end/103193
>         * match.pd: Avoid canonicalizing (le/ge @0 @0) to (eq @0 @0)
>         with NaNs and -ftrapping-math.
> ---
>  gcc/match.pd | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index a319aefa808..a7f1e56fe2f 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -4629,7 +4629,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>    (if (! FLOAT_TYPE_P (TREE_TYPE (@0))
>         || ! HONOR_NANS (@0))
>     { constant_boolean_node (true, type); }
> -   (if (cmp != EQ_EXPR)
> +   (if (cmp != EQ_EXPR
> +       /* With -ftrapping-math conversion to EQ loses an exception.  */
> +       && (! FLOAT_TYPE_P (TREE_TYPE (@0))
> +           || ! flag_trapping_math))
>      (eq @0 @0)))))
>  (for cmp (ne gt lt)
>   (simplify
> --
> 2.31.1
Jakub Jelinek Nov. 24, 2021, 9:03 a.m. UTC | #2
On Wed, Nov 24, 2021 at 10:00:56AM +0100, Richard Biener via Gcc-patches wrote:
> On Mon, Nov 15, 2021 at 12:16 PM Richard Biener via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > This avoids doing aforementioned canoncalization when -ftrapping-math
> > is in effect and we honor NaNs.
> >
> > Bootstrapped and tested on x86_64-unknown-linux-gnu.
> >
> > OK?
> 
> Ping.
> 
> >
> > Thanks,
> > Richard.
> >
> > 2021-11-15  Richard Biener  <rguenther@suse.de>
> >
> >         PR middle-end/103193
> >         * match.pd: Avoid canonicalizing (le/ge @0 @0) to (eq @0 @0)
> >         with NaNs and -ftrapping-math.

Ok, thanks.

> >  gcc/match.pd | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/gcc/match.pd b/gcc/match.pd
> > index a319aefa808..a7f1e56fe2f 100644
> > --- a/gcc/match.pd
> > +++ b/gcc/match.pd
> > @@ -4629,7 +4629,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> >    (if (! FLOAT_TYPE_P (TREE_TYPE (@0))
> >         || ! HONOR_NANS (@0))
> >     { constant_boolean_node (true, type); }
> > -   (if (cmp != EQ_EXPR)
> > +   (if (cmp != EQ_EXPR
> > +       /* With -ftrapping-math conversion to EQ loses an exception.  */
> > +       && (! FLOAT_TYPE_P (TREE_TYPE (@0))
> > +           || ! flag_trapping_math))
> >      (eq @0 @0)))))
> >  (for cmp (ne gt lt)
> >   (simplify
> > --
> > 2.31.1

	Jakub
diff mbox series

Patch

diff --git a/gcc/match.pd b/gcc/match.pd
index a319aefa808..a7f1e56fe2f 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4629,7 +4629,10 @@  DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (if (! FLOAT_TYPE_P (TREE_TYPE (@0))
        || ! HONOR_NANS (@0))
    { constant_boolean_node (true, type); }
-   (if (cmp != EQ_EXPR)
+   (if (cmp != EQ_EXPR
+	/* With -ftrapping-math conversion to EQ loses an exception.  */
+	&& (! FLOAT_TYPE_P (TREE_TYPE (@0))
+	    || ! flag_trapping_math))
     (eq @0 @0)))))
 (for cmp (ne gt lt)
  (simplify