public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
@ 2023-11-11 21:54 xry111 at gcc dot gnu.org
  2023-11-12 13:32 ` [Bug target/112483] " xry111 at gcc dot gnu.org
                   ` (22 more replies)
  0 siblings, 23 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-11 21:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

            Bug ID: 112483
           Summary: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on
                    loongarch64-linux-gnu at -O1 or above
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xry111 at gcc dot gnu.org
  Target Milestone: ---

With r14-5366 on loongarch64-linux-gnu:

FAIL: gfortran.dg/ieee/ieee_2.f90   -O1  execution test
FAIL: gfortran.dg/ieee/ieee_2.f90   -O2  execution test
FAIL: gfortran.dg/ieee/ieee_2.f90   -O3 -fomit-frame-pointer -funroll-loops
-fpeel-loops -ftracer -finline-functions  execution test
FAIL: gfortran.dg/ieee/ieee_2.f90   -O3 -g  execution test
FAIL: gfortran.dg/ieee/ieee_2.f90   -Os  execution test

This is a very recent regression but I've not bisected yet.  I'm not sure if
the component field is correct either.

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

* [Bug target/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
@ 2023-11-12 13:32 ` xry111 at gcc dot gnu.org
  2023-11-12 13:42 ` xry111 at gcc dot gnu.org
                   ` (21 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-12 13:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tamar.christina at arm dot com
   Last reconfirmed|                            |2023-11-12
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
First bad commit is r14-5284:

    middle-end: optimize fneg (fabs (x)) to copysign (x, -1) [PR109154]

    This patch transforms fneg (fabs (x)) into copysign (x, -1) which is more
    canonical and allows a target to expand this sequence efficiently.  Such
    sequences are common in scientific code working with gradients.

    There is an existing canonicalization of copysign (x, -1) to fneg (fabs
(x))
    which I remove since this is a less efficient form.  The testsuite is also
    updated in light of this.

    gcc/ChangeLog:

            PR tree-optimization/109154
            * match.pd: Add new neg+abs rule, remove inverse copysign rule.

    gcc/testsuite/ChangeLog:

            PR tree-optimization/109154
            * gcc.dg/fold-copysign-1.c: Updated.
            * gcc.dg/pr55152-2.c: Updated.
            * gcc.dg/tree-ssa/abs-4.c: Updated.
            * gcc.dg/tree-ssa/backprop-6.c: Updated.
            * gcc.dg/tree-ssa/copy-sign-2.c: Updated.
            * gcc.dg/tree-ssa/mult-abs-2.c: Updated.
            * gcc.target/aarch64/fneg-abs_1.c: New test.
            * gcc.target/aarch64/fneg-abs_2.c: New test.
            * gcc.target/aarch64/fneg-abs_3.c: New test.
            * gcc.target/aarch64/fneg-abs_4.c: New test.
            * gcc.target/aarch64/sve/fneg-abs_1.c: New test.
            * gcc.target/aarch64/sve/fneg-abs_2.c: New test.
            * gcc.target/aarch64/sve/fneg-abs_3.c: New test.
            * gcc.target/aarch64/sve/fneg-abs_4.c: New test.

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

* [Bug target/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
  2023-11-12 13:32 ` [Bug target/112483] " xry111 at gcc dot gnu.org
@ 2023-11-12 13:42 ` xry111 at gcc dot gnu.org
  2023-11-12 13:46 ` xry111 at gcc dot gnu.org
                   ` (20 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-12 13:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #2 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to Xi Ruoyao from comment #1)

>     gcc/ChangeLog:
>     
>             PR tree-optimization/109154
>             * match.pd: Add new neg+abs rule, remove inverse copysign rule.

I guess the inverse copysign rule removal caused a hidden issue to show up...

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

* [Bug target/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
  2023-11-12 13:32 ` [Bug target/112483] " xry111 at gcc dot gnu.org
  2023-11-12 13:42 ` xry111 at gcc dot gnu.org
@ 2023-11-12 13:46 ` xry111 at gcc dot gnu.org
  2023-11-12 13:54 ` xry111 at gcc dot gnu.org
                   ` (19 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-12 13:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #3 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
Minimized test case:

! { dg-do run }

  use, intrinsic :: ieee_arithmetic
  implicit none

  real :: sx1, sx2, sx3
  double precision :: dx1, dx2, dx3
  type(ieee_round_type) :: mode

  ! Test IEEE_COPY_SIGN
  sx1 = -tiny(sx1)
  sx1 = sx1 / 101
  if (ieee_copy_sign(sx1, sx1) /= sx1) STOP 37
end

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

* [Bug target/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-11-12 13:46 ` xry111 at gcc dot gnu.org
@ 2023-11-12 13:54 ` xry111 at gcc dot gnu.org
  2023-11-12 14:06 ` [Bug rtl-optimization/112483] " xry111 at gcc dot gnu.org
                   ` (18 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-12 13:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #4 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
In 268r.cse1:

(insn 26 25 27 2 (set (reg:SF 93)
        (mem/u/c:SF (reg/f:DI 94) [0  S4 A32])) "ieee_2.f90":13:6 discrim 4 146
{*movsf_hardfloat}
     (expr_list:REG_EQUAL (const_double:SF -1.0e+0 [-0x0.8p+1])
        (nil)))
(insn 27 26 28 2 (set (reg:SF 81 [ _8 ])
        (copysign:SF (reg/v:SF 80 [ sx1 ])
            (reg:SF 93))) "ieee_2.f90":13:6 discrim 4 63 {copysignsf3}
     (nil))

But in 269r.fwprop1:

(insn 27 24 28 2 (set (reg:SF 81 [ _8 ])
        (neg:SF (reg/v:SF 80 [ sx1 ]))) "ieee_2.f90":13:6 discrim 4 89 {negsf2}
     (expr_list:REG_DEAD (reg:SF 93)
        (nil)))

???

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-11-12 13:54 ` xry111 at gcc dot gnu.org
@ 2023-11-12 14:06 ` xry111 at gcc dot gnu.org
  2023-11-12 18:57 ` tschwinge at gcc dot gnu.org
                   ` (17 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-12 14:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|target                      |rtl-optimization

--- Comment #5 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
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 (&f1, 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??

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-11-12 14:06 ` [Bug rtl-optimization/112483] " xry111 at gcc dot gnu.org
@ 2023-11-12 18:57 ` tschwinge at gcc dot gnu.org
  2023-11-12 19:25 ` tnfchris at gcc dot gnu.org
                   ` (16 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: tschwinge at gcc dot gnu.org @ 2023-11-12 18:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Thomas Schwinge <tschwinge at gcc dot gnu.org> 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 <tschwinge at gcc dot gnu.org> ---
(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 (&f1, 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

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-11-12 18:57 ` tschwinge at gcc dot gnu.org
@ 2023-11-12 19:25 ` tnfchris at gcc dot gnu.org
  2023-11-12 19:26 ` xry111 at gcc dot gnu.org
                   ` (15 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2023-11-12 19:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Tamar Christina <tnfchris at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tnfchris at gcc dot gnu.org

--- Comment #7 from Tamar Christina <tnfchris at gcc dot gnu.org> ---
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?

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-11-12 19:25 ` tnfchris at gcc dot gnu.org
@ 2023-11-12 19:26 ` xry111 at gcc dot gnu.org
  2023-11-12 20:22 ` xry111 at gcc dot gnu.org
                   ` (14 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-12 19:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #8 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(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.

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2023-11-12 19:26 ` xry111 at gcc dot gnu.org
@ 2023-11-12 20:22 ` xry111 at gcc dot gnu.org
  2023-11-12 20:27 ` xry111 at gcc dot gnu.org
                   ` (13 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-12 20:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #9 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
*** Bug 112484 has been marked as a duplicate of this bug. ***

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2023-11-12 20:22 ` xry111 at gcc dot gnu.org
@ 2023-11-12 20:27 ` xry111 at gcc dot gnu.org
  2023-11-12 21:16 ` pinskia at gcc dot gnu.org
                   ` (12 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-12 20:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Xi Ruoyao <xry111 at gcc dot gnu.org> 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 <xry111 at gcc dot gnu.org> ---
(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

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2023-11-12 20:27 ` xry111 at gcc dot gnu.org
@ 2023-11-12 21:16 ` pinskia at gcc dot gnu.org
  2023-11-13  7:40 ` xry111 at gcc dot gnu.org
                   ` (11 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-12 21:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.0
           Keywords|                            |wrong-code

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (10 preceding siblings ...)
  2023-11-12 21:16 ` pinskia at gcc dot gnu.org
@ 2023-11-13  7:40 ` xry111 at gcc dot gnu.org
  2023-11-13  7:46 ` pinskia at gcc dot gnu.org
                   ` (10 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-13  7:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization

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

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (11 preceding siblings ...)
  2023-11-13  7:40 ` xry111 at gcc dot gnu.org
@ 2023-11-13  7:46 ` pinskia at gcc dot gnu.org
  2023-11-13  7:52 ` cvs-commit at gcc dot gnu.org
                   ` (9 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-13  7:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
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 (&f1, 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.

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (12 preceding siblings ...)
  2023-11-13  7:46 ` pinskia at gcc dot gnu.org
@ 2023-11-13  7:52 ` cvs-commit at gcc dot gnu.org
  2023-11-13  7:53 ` xry111 at gcc dot gnu.org
                   ` (8 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-13  7:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #13 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Xi Ruoyao <xry111@gcc.gnu.org>:

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

commit r14-5377-g7ba7529ee3974667a8e68d089b606ac2fb159415
Author: Xi Ruoyao <xry111@xry111.site>
Date:   Sun Nov 12 14:16:20 2023 +0000

    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) <case COPYSIGN>:
            Fix the simplification of (fcopysign x, NEGATIVE_CONST).

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (13 preceding siblings ...)
  2023-11-13  7:52 ` cvs-commit at gcc dot gnu.org
@ 2023-11-13  7:53 ` xry111 at gcc dot gnu.org
  2023-11-13  7:54 ` tnfchris at gcc dot gnu.org
                   ` (7 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-13  7:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Xi Ruoyao <xry111 at gcc dot gnu.org> 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 <xry111 at gcc dot gnu.org> ---
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.

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (14 preceding siblings ...)
  2023-11-13  7:53 ` xry111 at gcc dot gnu.org
@ 2023-11-13  7:54 ` tnfchris at gcc dot gnu.org
  2023-11-13  8:03 ` xry111 at gcc dot gnu.org
                   ` (6 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2023-11-13  7:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Tamar Christina <tnfchris at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|tamar.christina at arm dot com     |

--- Comment #15 from Tamar Christina <tnfchris at gcc dot gnu.org> ---
removing duplicate mail

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (15 preceding siblings ...)
  2023-11-13  7:54 ` tnfchris at gcc dot gnu.org
@ 2023-11-13  8:03 ` xry111 at gcc dot gnu.org
  2023-11-13  8:10 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-13  8:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #16 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(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 (&f1, 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.

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (16 preceding siblings ...)
  2023-11-13  8:03 ` xry111 at gcc dot gnu.org
@ 2023-11-13  8:10 ` rguenth at gcc dot gnu.org
  2023-11-13  8:44 ` xry111 at gcc dot gnu.org
                   ` (4 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-11-13  8:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P4

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (17 preceding siblings ...)
  2023-11-13  8:10 ` rguenth at gcc dot gnu.org
@ 2023-11-13  8:44 ` xry111 at gcc dot gnu.org
  2023-11-13 18:42 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-13  8:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #17 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(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 (&f1, 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?

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (18 preceding siblings ...)
  2023-11-13  8:44 ` xry111 at gcc dot gnu.org
@ 2023-11-13 18:42 ` pinskia at gcc dot gnu.org
  2023-11-14 10:06 ` xry111 at gcc dot gnu.org
                   ` (2 subsequent siblings)
  22 siblings, 0 replies; 24+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-13 18:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #18 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(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?

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (19 preceding siblings ...)
  2023-11-13 18:42 ` pinskia at gcc dot gnu.org
@ 2023-11-14 10:06 ` xry111 at gcc dot gnu.org
  2023-11-16 23:46 ` cvs-commit at gcc dot gnu.org
  2023-11-16 23:46 ` xry111 at gcc dot gnu.org
  22 siblings, 0 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-14 10:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #19 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(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

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (20 preceding siblings ...)
  2023-11-14 10:06 ` xry111 at gcc dot gnu.org
@ 2023-11-16 23:46 ` cvs-commit at gcc dot gnu.org
  2023-11-16 23:46 ` xry111 at gcc dot gnu.org
  22 siblings, 0 replies; 24+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-16 23:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

--- Comment #20 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Xi Ruoyao <xry111@gcc.gnu.org>:

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

commit r14-5542-g9e9279fadbd1c673c875b9d20261d2de0473f63f
Author: Andrew Pinski <pinskia@gmail.com>
Date:   Mon Nov 13 20:18:34 2023 +0000

    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) <case COPYSIGN>:
            Call simplify_unary_operation for NEG instead of
            simplify_gen_unary.

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

* [Bug rtl-optimization/112483] [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above
  2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
                   ` (21 preceding siblings ...)
  2023-11-16 23:46 ` cvs-commit at gcc dot gnu.org
@ 2023-11-16 23:46 ` xry111 at gcc dot gnu.org
  22 siblings, 0 replies; 24+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-16 23:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112483

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #21 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
The de-optimization is fixed as well.  Closing.

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

end of thread, other threads:[~2023-11-16 23:46 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-11 21:54 [Bug target/112483] New: [14 Regression] gfortran.dg/ieee/ieee_2.f90 fails on loongarch64-linux-gnu at -O1 or above xry111 at gcc dot gnu.org
2023-11-12 13:32 ` [Bug target/112483] " xry111 at gcc dot gnu.org
2023-11-12 13:42 ` xry111 at gcc dot gnu.org
2023-11-12 13:46 ` xry111 at gcc dot gnu.org
2023-11-12 13:54 ` xry111 at gcc dot gnu.org
2023-11-12 14:06 ` [Bug rtl-optimization/112483] " xry111 at gcc dot gnu.org
2023-11-12 18:57 ` tschwinge at gcc dot gnu.org
2023-11-12 19:25 ` tnfchris at gcc dot gnu.org
2023-11-12 19:26 ` xry111 at gcc dot gnu.org
2023-11-12 20:22 ` xry111 at gcc dot gnu.org
2023-11-12 20:27 ` xry111 at gcc dot gnu.org
2023-11-12 21:16 ` pinskia at gcc dot gnu.org
2023-11-13  7:40 ` xry111 at gcc dot gnu.org
2023-11-13  7:46 ` pinskia at gcc dot gnu.org
2023-11-13  7:52 ` cvs-commit at gcc dot gnu.org
2023-11-13  7:53 ` xry111 at gcc dot gnu.org
2023-11-13  7:54 ` tnfchris at gcc dot gnu.org
2023-11-13  8:03 ` xry111 at gcc dot gnu.org
2023-11-13  8:10 ` rguenth at gcc dot gnu.org
2023-11-13  8:44 ` xry111 at gcc dot gnu.org
2023-11-13 18:42 ` pinskia at gcc dot gnu.org
2023-11-14 10:06 ` xry111 at gcc dot gnu.org
2023-11-16 23:46 ` cvs-commit at gcc dot gnu.org
2023-11-16 23:46 ` xry111 at gcc dot gnu.org

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