public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] Fold: Fix up merge_truthop_with_opposite_arm for NaNs [PR95351]
@ 2024-03-11  2:58 Andrew Pinski
  2024-03-12  6:40 ` Andrew Pinski (QUIC)
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Pinski @ 2024-03-11  2:58 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew Pinski

The problem here is that merge_truthop_with_opposite_arm would
use the type of the result of the comparison rather than the operands
of the comparison to figure out if we are honoring NaNs.
This fixes that oversight and now we get the correct results in this
case.

Committed as obvious after a bootstrap/test on x86_64-linux-gnu.

	PR middle-end/95351

gcc/ChangeLog:

	* fold-const.cc (merge_truthop_with_opposite_arm): Use
	the type of the operands of the comparison and not the type
	of the comparison.

gcc/testsuite/ChangeLog:

	* gcc.dg/float_opposite_arm-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
---
 gcc/fold-const.cc                           |  3 ++-
 gcc/testsuite/gcc.dg/float_opposite_arm-1.c | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/float_opposite_arm-1.c

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 43105d20be3..299c22bf391 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -6420,7 +6420,6 @@ static tree
 merge_truthop_with_opposite_arm (location_t loc, tree op, tree cmpop,
 				 bool rhs_only)
 {
-  tree type = TREE_TYPE (cmpop);
   enum tree_code code = TREE_CODE (cmpop);
   enum tree_code truthop_code = TREE_CODE (op);
   tree lhs = TREE_OPERAND (op, 0);
@@ -6436,6 +6435,8 @@ merge_truthop_with_opposite_arm (location_t loc, tree op, tree cmpop,
   if (TREE_CODE_CLASS (code) != tcc_comparison)
     return NULL_TREE;
 
+  tree type = TREE_TYPE (TREE_OPERAND (cmpop, 0));
+
   if (rhs_code == truthop_code)
     {
       tree newrhs = merge_truthop_with_opposite_arm (loc, rhs, cmpop, rhs_only);
diff --git a/gcc/testsuite/gcc.dg/float_opposite_arm-1.c b/gcc/testsuite/gcc.dg/float_opposite_arm-1.c
new file mode 100644
index 00000000000..d2dbff35066
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/float_opposite_arm-1.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-original -fdump-tree-optimized" } */
+/* { dg-add-options ieee } */
+/* PR middle-end/95351 */
+
+int Foo(double possiblyNAN, double b, double c)
+{
+    return (possiblyNAN <= 2.0) || ((possiblyNAN  > 2.0) && (b > c));
+}
+
+/* Make sure we don't remove either >/<=  */
+
+/* { dg-final { scan-tree-dump "possiblyNAN > 2.0e.0" "original" } } */
+/* { dg-final { scan-tree-dump "possiblyNAN_\[0-9\]+.D. > 2.0e.0" "optimized" } } */
+
+/* { dg-final { scan-tree-dump "possiblyNAN <= 2.0e.0" "original" } } */
+/* { dg-final { scan-tree-dump "possiblyNAN_\[0-9\]+.D. <= 2.0e.0" "optimized" } } */
-- 
2.43.0


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

* RE: [COMMITTED] Fold: Fix up merge_truthop_with_opposite_arm for NaNs [PR95351]
  2024-03-11  2:58 [COMMITTED] Fold: Fix up merge_truthop_with_opposite_arm for NaNs [PR95351] Andrew Pinski
@ 2024-03-12  6:40 ` Andrew Pinski (QUIC)
  2024-05-08 16:19   ` Andrew Pinski
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Pinski (QUIC) @ 2024-03-12  6:40 UTC (permalink / raw)
  To: Andrew Pinski (QUIC), gcc-patches

> -----Original Message-----
> From: Andrew Pinski (QUIC) <quic_apinski@quicinc.com>
> Sent: Sunday, March 10, 2024 7:58 PM
> To: gcc-patches@gcc.gnu.org
> Cc: Andrew Pinski (QUIC) <quic_apinski@quicinc.com>
> Subject: [COMMITTED] Fold: Fix up merge_truthop_with_opposite_arm for
> NaNs [PR95351]
> 
> The problem here is that merge_truthop_with_opposite_arm would use the
> type of the result of the comparison rather than the operands of the
> comparison to figure out if we are honoring NaNs.
> This fixes that oversight and now we get the correct results in this case.
> 
> Committed as obvious after a bootstrap/test on x86_64-linux-gnu.

Committed to the GCC 13 branch too.

Thanks,
Andrew

> 
> 	PR middle-end/95351
> 
> gcc/ChangeLog:
> 
> 	* fold-const.cc (merge_truthop_with_opposite_arm): Use
> 	the type of the operands of the comparison and not the type
> 	of the comparison.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.dg/float_opposite_arm-1.c: New test.
> 
> Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
> ---
>  gcc/fold-const.cc                           |  3 ++-
>  gcc/testsuite/gcc.dg/float_opposite_arm-1.c | 17 +++++++++++++++++
>  2 files changed, 19 insertions(+), 1 deletion(-)  create mode 100644
> gcc/testsuite/gcc.dg/float_opposite_arm-1.c
> 
> diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index
> 43105d20be3..299c22bf391 100644
> --- a/gcc/fold-const.cc
> +++ b/gcc/fold-const.cc
> @@ -6420,7 +6420,6 @@ static tree
>  merge_truthop_with_opposite_arm (location_t loc, tree op, tree cmpop,
>  				 bool rhs_only)
>  {
> -  tree type = TREE_TYPE (cmpop);
>    enum tree_code code = TREE_CODE (cmpop);
>    enum tree_code truthop_code = TREE_CODE (op);
>    tree lhs = TREE_OPERAND (op, 0);
> @@ -6436,6 +6435,8 @@ merge_truthop_with_opposite_arm (location_t
> loc, tree op, tree cmpop,
>    if (TREE_CODE_CLASS (code) != tcc_comparison)
>      return NULL_TREE;
> 
> +  tree type = TREE_TYPE (TREE_OPERAND (cmpop, 0));
> +
>    if (rhs_code == truthop_code)
>      {
>        tree newrhs = merge_truthop_with_opposite_arm (loc, rhs, cmpop,
> rhs_only); diff --git a/gcc/testsuite/gcc.dg/float_opposite_arm-1.c
> b/gcc/testsuite/gcc.dg/float_opposite_arm-1.c
> new file mode 100644
> index 00000000000..d2dbff35066
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/float_opposite_arm-1.c
> @@ -0,0 +1,17 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O1 -fdump-tree-original -fdump-tree-optimized" } */
> +/* { dg-add-options ieee } */
> +/* PR middle-end/95351 */
> +
> +int Foo(double possiblyNAN, double b, double c) {
> +    return (possiblyNAN <= 2.0) || ((possiblyNAN  > 2.0) && (b > c)); }
> +
> +/* Make sure we don't remove either >/<=  */
> +
> +/* { dg-final { scan-tree-dump "possiblyNAN > 2.0e.0" "original" } } */
> +/* { dg-final { scan-tree-dump "possiblyNAN_\[0-9\]+.D. > 2.0e.0"
> +"optimized" } } */
> +
> +/* { dg-final { scan-tree-dump "possiblyNAN <= 2.0e.0" "original" } }
> +*/
> +/* { dg-final { scan-tree-dump "possiblyNAN_\[0-9\]+.D. <= 2.0e.0"
> +"optimized" } } */
> --
> 2.43.0


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

* Re: [COMMITTED] Fold: Fix up merge_truthop_with_opposite_arm for NaNs [PR95351]
  2024-03-12  6:40 ` Andrew Pinski (QUIC)
@ 2024-05-08 16:19   ` Andrew Pinski
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Pinski @ 2024-05-08 16:19 UTC (permalink / raw)
  To: Andrew Pinski (QUIC); +Cc: gcc-patches

On Mon, Mar 11, 2024 at 11:41 PM Andrew Pinski (QUIC)
<quic_apinski@quicinc.com> wrote:
>
> > -----Original Message-----
> > From: Andrew Pinski (QUIC) <quic_apinski@quicinc.com>
> > Sent: Sunday, March 10, 2024 7:58 PM
> > To: gcc-patches@gcc.gnu.org
> > Cc: Andrew Pinski (QUIC) <quic_apinski@quicinc.com>
> > Subject: [COMMITTED] Fold: Fix up merge_truthop_with_opposite_arm for
> > NaNs [PR95351]
> >
> > The problem here is that merge_truthop_with_opposite_arm would use the
> > type of the result of the comparison rather than the operands of the
> > comparison to figure out if we are honoring NaNs.
> > This fixes that oversight and now we get the correct results in this case.
> >
> > Committed as obvious after a bootstrap/test on x86_64-linux-gnu.
>
> Committed to the GCC 13 branch too.

And the GCC 12 and 11 branches too.


>
> Thanks,
> Andrew
>
> >
> >       PR middle-end/95351
> >
> > gcc/ChangeLog:
> >
> >       * fold-const.cc (merge_truthop_with_opposite_arm): Use
> >       the type of the operands of the comparison and not the type
> >       of the comparison.
> >
> > gcc/testsuite/ChangeLog:
> >
> >       * gcc.dg/float_opposite_arm-1.c: New test.
> >
> > Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
> > ---
> >  gcc/fold-const.cc                           |  3 ++-
> >  gcc/testsuite/gcc.dg/float_opposite_arm-1.c | 17 +++++++++++++++++
> >  2 files changed, 19 insertions(+), 1 deletion(-)  create mode 100644
> > gcc/testsuite/gcc.dg/float_opposite_arm-1.c
> >
> > diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index
> > 43105d20be3..299c22bf391 100644
> > --- a/gcc/fold-const.cc
> > +++ b/gcc/fold-const.cc
> > @@ -6420,7 +6420,6 @@ static tree
> >  merge_truthop_with_opposite_arm (location_t loc, tree op, tree cmpop,
> >                                bool rhs_only)
> >  {
> > -  tree type = TREE_TYPE (cmpop);
> >    enum tree_code code = TREE_CODE (cmpop);
> >    enum tree_code truthop_code = TREE_CODE (op);
> >    tree lhs = TREE_OPERAND (op, 0);
> > @@ -6436,6 +6435,8 @@ merge_truthop_with_opposite_arm (location_t
> > loc, tree op, tree cmpop,
> >    if (TREE_CODE_CLASS (code) != tcc_comparison)
> >      return NULL_TREE;
> >
> > +  tree type = TREE_TYPE (TREE_OPERAND (cmpop, 0));
> > +
> >    if (rhs_code == truthop_code)
> >      {
> >        tree newrhs = merge_truthop_with_opposite_arm (loc, rhs, cmpop,
> > rhs_only); diff --git a/gcc/testsuite/gcc.dg/float_opposite_arm-1.c
> > b/gcc/testsuite/gcc.dg/float_opposite_arm-1.c
> > new file mode 100644
> > index 00000000000..d2dbff35066
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/float_opposite_arm-1.c
> > @@ -0,0 +1,17 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O1 -fdump-tree-original -fdump-tree-optimized" } */
> > +/* { dg-add-options ieee } */
> > +/* PR middle-end/95351 */
> > +
> > +int Foo(double possiblyNAN, double b, double c) {
> > +    return (possiblyNAN <= 2.0) || ((possiblyNAN  > 2.0) && (b > c)); }
> > +
> > +/* Make sure we don't remove either >/<=  */
> > +
> > +/* { dg-final { scan-tree-dump "possiblyNAN > 2.0e.0" "original" } } */
> > +/* { dg-final { scan-tree-dump "possiblyNAN_\[0-9\]+.D. > 2.0e.0"
> > +"optimized" } } */
> > +
> > +/* { dg-final { scan-tree-dump "possiblyNAN <= 2.0e.0" "original" } }
> > +*/
> > +/* { dg-final { scan-tree-dump "possiblyNAN_\[0-9\]+.D. <= 2.0e.0"
> > +"optimized" } } */
> > --
> > 2.43.0
>

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

end of thread, other threads:[~2024-05-08 16:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-11  2:58 [COMMITTED] Fold: Fix up merge_truthop_with_opposite_arm for NaNs [PR95351] Andrew Pinski
2024-03-12  6:40 ` Andrew Pinski (QUIC)
2024-05-08 16:19   ` 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).