[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-16 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Xi Ruoyao  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #21 from Xi Ruoyao  ---
The de-optimization is fixed as well.  Closing.

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-16 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #20 from CVS Commits  ---
The master branch has been updated by Xi Ruoyao :

https://gcc.gnu.org/g:9e9279fadbd1c673c875b9d20261d2de0473f63f

commit r14-5542-g9e9279fadbd1c673c875b9d20261d2de0473f63f
Author: Andrew Pinski 
Date:   Mon Nov 13 20:18:34 2023 +

Only allow (copysign x, NEG_CONST) -> (fneg (fabs x)) simplification for
constant folding [PR112483]

On targets with native copysign instructions, (copysign x, -1) is
usually more efficient than (fneg (fabs x)).  Since r14-5284, in the
middle end we always optimize (fneg (fabs x)) to (copysign x, -1), not
vice versa.  If the target does not support native fcopysign,
expand_COPYSIGN will expand it as (fneg (fabs x)) anyway.

gcc/ChangeLog:

PR rtl-optimization/112483
* simplify-rtx.cc (simplify_binary_operation_1) :
Call simplify_unary_operation for NEG instead of
simplify_gen_unary.

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-14 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #19 from Xi Ruoyao  ---
(In reply to Andrew Pinski from comment #18)
> (In reply to Xi Ruoyao from comment #17) 
> > Works for me.  Will you send the simplify_gen_unary ->
> > simplify_unary_operation change to gcc-patches?
> 
> I don't have a platform where it makes a difference to test on. Can you post
> it?

https://gcc.gnu.org/pipermail/gcc-patches/2023-November/636445.html

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-13 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #18 from Andrew Pinski  ---
(In reply to Xi Ruoyao from comment #17) 
> Works for me.  Will you send the simplify_gen_unary ->
> simplify_unary_operation change to gcc-patches?

I don't have a platform where it makes a difference to test on. Can you post
it?

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-13 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #17 from Xi Ruoyao  ---
(In reply to Xi Ruoyao from comment #16)
> (In reply to Andrew Pinski from comment #12)
> > What about this patch:
> > ```
> > diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
> > index 69d87579d9c..f3745d86aea 100644
> > --- a/gcc/simplify-rtx.cc
> > +++ b/gcc/simplify-rtx.cc
> > @@ -4392,7 +4392,7 @@ simplify_ashift:
> >   real_convert (, mode, CONST_DOUBLE_REAL_VALUE (trueop1));
> >   rtx tmp = simplify_gen_unary (ABS, mode, op0, mode);
> >   if (REAL_VALUE_NEGATIVE (f1))
> > -   tmp = simplify_gen_unary (NEG, mode, op0, mode);
> > +   tmp = simplify_unary_operation (NEG, mode, tmp, mode);
> >   return tmp;
> > }
> >if (GET_CODE (op0) == NEG || GET_CODE (op0) == ABS)
> > 
> > ```
> > 
> > We only generate NEG if it simplifies from the ABS. Most likely due to
> > constants.
> 
> I'm trying this out on LoongArch.

Works for me.  Will you send the simplify_gen_unary -> simplify_unary_operation
change to gcc-patches?

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-13 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P4

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-13 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #16 from Xi Ruoyao  ---
(In reply to Andrew Pinski from comment #12)
> What about this patch:
> ```
> diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
> index 69d87579d9c..f3745d86aea 100644
> --- a/gcc/simplify-rtx.cc
> +++ b/gcc/simplify-rtx.cc
> @@ -4392,7 +4392,7 @@ simplify_ashift:
>   real_convert (, mode, CONST_DOUBLE_REAL_VALUE (trueop1));
>   rtx tmp = simplify_gen_unary (ABS, mode, op0, mode);
>   if (REAL_VALUE_NEGATIVE (f1))
> -   tmp = simplify_gen_unary (NEG, mode, op0, mode);
> +   tmp = simplify_unary_operation (NEG, mode, tmp, mode);
>   return tmp;
> }
>if (GET_CODE (op0) == NEG || GET_CODE (op0) == ABS)
> 
> ```
> 
> We only generate NEG if it simplifies from the ABS. Most likely due to
> constants.

I'm trying this out on LoongArch.

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-12 Thread tnfchris at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Tamar Christina  changed:

   What|Removed |Added

 CC|tamar.christina at arm dot com |

--- Comment #15 from Tamar Christina  ---
removing duplicate mail

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-12 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Xi Ruoyao  changed:

   What|Removed |Added

 Status|ASSIGNED|NEW
   Assignee|xry111 at gcc dot gnu.org  |unassigned at gcc dot 
gnu.org

--- Comment #14 from Xi Ruoyao  ---
I've pushed the obvious fix for now (as the wrong-code issue is causing
wide-spreading test failures).  Leaving the ticket open for the
missed-optimization.

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-12 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #13 from CVS Commits  ---
The master branch has been updated by Xi Ruoyao :

https://gcc.gnu.org/g:7ba7529ee3974667a8e68d089b606ac2fb159415

commit r14-5377-g7ba7529ee3974667a8e68d089b606ac2fb159415
Author: Xi Ruoyao 
Date:   Sun Nov 12 14:16:20 2023 +

Fix (fcopysign x, NEGATIVE_CONST) -> (fneg (fabs x)) simplification
[PR112483]

(fcopysign x, NEGATIVE_CONST) can be simplified to (fneg (fabs x)), but
a logic error in the code caused it mistakenly simplified to (fneg x)
instead.

gcc/ChangeLog:

PR rtl-optimization/112483
* simplify-rtx.cc (simplify_binary_operation_1) :
Fix the simplification of (fcopysign x, NEGATIVE_CONST).

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-12 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #12 from Andrew Pinski  ---
What about this patch:
```
diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index 69d87579d9c..f3745d86aea 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -4392,7 +4392,7 @@ simplify_ashift:
  real_convert (, mode, CONST_DOUBLE_REAL_VALUE (trueop1));
  rtx tmp = simplify_gen_unary (ABS, mode, op0, mode);
  if (REAL_VALUE_NEGATIVE (f1))
-   tmp = simplify_gen_unary (NEG, mode, op0, mode);
+   tmp = simplify_unary_operation (NEG, mode, tmp, mode);
  return tmp;
}
   if (GET_CODE (op0) == NEG || GET_CODE (op0) == ABS)

```

We only generate NEG if it simplifies from the ABS. Most likely due to
constants.

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-12 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Xi Ruoyao  changed:

   What|Removed |Added

   Keywords||missed-optimization

--- Comment #11 from Xi Ruoyao  ---
As we've discussed via gcc-patches, the (fcopysign x, NEG_CONST) -> (fneg (fabs
x)) conversion seems a de-optimization.

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-12 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |14.0
   Keywords||wrong-code

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-12 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Xi Ruoyao  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |xry111 at gcc dot 
gnu.org
 Status|NEW |ASSIGNED
   Keywords||patch
URL||https://gcc.gnu.org/piperma
   ||il/gcc-patches/2023-Novembe
   ||r/636200.html

--- Comment #10 from Xi Ruoyao  ---
(In reply to Xi Ruoyao from comment #8)
> (In reply to Tamar Christina from comment #7)
> > Yeah, that fold-rtx code is bogus. It's a latent bug.
> > 
> > Optimizing copysign(x, -y) to neg(x) is just wrong.
> > 
> > Will you be sending a patch Xi or do you want me to?
> 
> Yes, I'm running a regression test now and I'll send the patch after it
> finishes.

https://gcc.gnu.org/pipermail/gcc-patches/2023-November/636200.html

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-12 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #9 from Xi Ruoyao  ---
*** Bug 112484 has been marked as a duplicate of this bug. ***

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-12 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #8 from Xi Ruoyao  ---
(In reply to Tamar Christina from comment #7)
> Yeah, that fold-rtx code is bogus. It's a latent bug.
> 
> Optimizing copysign(x, -y) to neg(x) is just wrong.
> 
> Will you be sending a patch Xi or do you want me to?

Yes, I'm running a regression test now and I'll send the patch after it
finishes.

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-12 Thread tnfchris at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Tamar Christina  changed:

   What|Removed |Added

 CC||tnfchris at gcc dot gnu.org

--- Comment #7 from Tamar Christina  ---
Yeah, that fold-rtx code is bogus. It's a latent bug.

Optimizing copysign(x, -y) to neg(x) is just wrong.

Will you be sending a patch Xi or do you want me to?

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-12 Thread tschwinge at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Thomas Schwinge  changed:

   What|Removed |Added

 Target|loongarch64-linux-gnu   |loongarch64-linux-gnu
   ||powerpc64le-linux-gnu
 CC||tschwinge at gcc dot gnu.org

--- Comment #6 from Thomas Schwinge  ---
(In reply to Xi Ruoyao from comment #5)
> In simplify_binary_operation_1, simplify-rtx.cc:
> 
> case COPYSIGN:
>   if (rtx_equal_p (trueop0, trueop1) && ! side_effects_p (op0))
> return op0; 
>   if (CONST_DOUBLE_AS_FLOAT_P (trueop1))
> {
>   REAL_VALUE_TYPE f1;
>   real_convert (, mode, CONST_DOUBLE_REAL_VALUE (trueop1));
>   rtx tmp = simplify_gen_unary (ABS, mode, op0, mode);
>   if (REAL_VALUE_NEGATIVE (f1))
> tmp = simplify_gen_unary (NEG, mode, op0, mode);
>  ^^^
>   return tmp; 
> }
> 
> shouldn't the "op0" with caret be "tmp" instead??

I have no knowledge at all about that code, but your suggested change appears
legit, and I do confirm that it does fix the following powerpc64le-linux-gnu
regressions:

@@ -169421,7 +169467,7 @@ PASS: gcc.target/powerpc/p8vector-fp.c
scan-assembler xsdivdp
PASS: gcc.target/powerpc/p8vector-fp.c scan-assembler xsdivsp
PASS: gcc.target/powerpc/p8vector-fp.c scan-assembler xsmuldp
PASS: gcc.target/powerpc/p8vector-fp.c scan-assembler xsmulsp
[-PASS:-]{+FAIL:+} gcc.target/powerpc/p8vector-fp.c scan-assembler xsnabsdp
PASS: gcc.target/powerpc/p8vector-fp.c scan-assembler xsnegdp
PASS: gcc.target/powerpc/p8vector-fp.c scan-assembler xssqrtdp
PASS: gcc.target/powerpc/p8vector-fp.c scan-assembler xssqrtsp

PASS: gfortran.dg/ieee/ieee_2.f90   -O0  (test for excess errors)
PASS: gfortran.dg/ieee/ieee_2.f90   -O0  execution test
PASS: gfortran.dg/ieee/ieee_2.f90   -O1  (test for excess errors)
[-PASS:-]{+FAIL:+} gfortran.dg/ieee/ieee_2.f90   -O1  execution test
PASS: gfortran.dg/ieee/ieee_2.f90   -O2  (test for excess errors)
PASS: gfortran.dg/ieee/ieee_2.f90   -O2  execution test
PASS: gfortran.dg/ieee/ieee_2.f90   -O3 -fomit-frame-pointer -funroll-loops
-fpeel-loops -ftracer -finline-functions  (test for excess errors)
@@ -63715,7 +63751,7 @@ PASS: gfortran.dg/ieee/ieee_2.f90   -O3
-fomit-frame-pointer -funroll-loops -fpe
PASS: gfortran.dg/ieee/ieee_2.f90   -O3 -g  (test for excess errors)
PASS: gfortran.dg/ieee/ieee_2.f90   -O3 -g  execution test
PASS: gfortran.dg/ieee/ieee_2.f90   -Os  (test for excess errors)
[-PASS:-]{+FAIL:+} gfortran.dg/ieee/ieee_2.f90   -Os  execution test

[Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above

2023-11-12 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Xi Ruoyao  changed:

   What|Removed |Added

  Component|target  |rtl-optimization

--- Comment #5 from Xi Ruoyao  ---
In simplify_binary_operation_1, simplify-rtx.cc:

case COPYSIGN:
  if (rtx_equal_p (trueop0, trueop1) && ! side_effects_p (op0))
return op0; 
  if (CONST_DOUBLE_AS_FLOAT_P (trueop1))
{
  REAL_VALUE_TYPE f1;
  real_convert (, mode, CONST_DOUBLE_REAL_VALUE (trueop1));
  rtx tmp = simplify_gen_unary (ABS, mode, op0, mode);
  if (REAL_VALUE_NEGATIVE (f1))
tmp = simplify_gen_unary (NEG, mode, op0, mode);
 ^^^
  return tmp; 
}

shouldn't the "op0" with caret be "tmp" instead??