public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/24964]  New: Does not optimise abs(x)**2 to x**2
@ 2005-11-20 23:54 schnetter at aei dot mpg dot de
  2005-11-21  0:40 ` [Bug tree-optimization/24964] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: schnetter at aei dot mpg dot de @ 2005-11-20 23:54 UTC (permalink / raw)
  To: gcc-bugs

I use

$ ~/gcc/bin/gcc --version
gcc (GCC) 4.2.0 20051119 (experimental)

on the routine

double precision function abssqr (a)
  implicit none
  double precision, intent(in) :: a
  abssqr = abs(a) ** 2
end function abssqr

with

$ ~/gcc/bin/gfortran -Wall -O3 -ffast-math -S abssqr.f90 

which leads to the assembler output

        .machine ppc
        .text
        .align 2
        .globl _abssqr_
_abssqr_:
        lfd f1,0(r3)
        fabs f1,f1
        fmul f1,f1,f1
        blr
        .subsections_via_symbols

I think that the term "abs(a)**2" should have been optimised to "a**2".  I
think that this optimisation is valid even with IEEE semantics, but I would
expect it anyway with -ffast-math.


-- 
           Summary: Does not optimise abs(x)**2 to x**2
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: schnetter at aei dot mpg dot de
 GCC build triplet: powerpc-apple-darwin8.3.0
  GCC host triplet: powerpc-apple-darwin8.3.0
GCC target triplet: powerpc-apple-darwin8.3.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24964


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

* [Bug tree-optimization/24964] Does not optimise abs(x)**2 to x**2
  2005-11-20 23:54 [Bug fortran/24964] New: Does not optimise abs(x)**2 to x**2 schnetter at aei dot mpg dot de
@ 2005-11-21  0:40 ` pinskia at gcc dot gnu dot org
  2006-05-29 16:22 ` sayle at gcc dot gnu dot org
  2006-05-29 21:24 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-11-21  0:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2005-11-21 00:40 -------
This comes down to the tree-combiner.
Take the following C functions:
double fabs(double);
double f(double a)
{
  return fabs(a)*fabs(a);
}

double f1(double *a)
{
  return fabs(*a)*fabs(*a);
}

double f2(double *a)
{
  double t = fabs(*a);
  return t*t;
}


Only f2 is not optimized.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |15459
             Status|UNCONFIRMED                 |NEW
          Component|fortran                     |tree-optimization
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-11-21 00:40:07
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24964


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

* [Bug tree-optimization/24964] Does not optimise abs(x)**2 to x**2
  2005-11-20 23:54 [Bug fortran/24964] New: Does not optimise abs(x)**2 to x**2 schnetter at aei dot mpg dot de
  2005-11-21  0:40 ` [Bug tree-optimization/24964] " pinskia at gcc dot gnu dot org
@ 2006-05-29 16:22 ` sayle at gcc dot gnu dot org
  2006-05-29 21:24 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: sayle at gcc dot gnu dot org @ 2006-05-29 16:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from sayle at gcc dot gnu dot org  2006-05-29 16:22 -------
Subject: Bug 24964

Author: sayle
Date: Mon May 29 16:22:05 2006
New Revision: 114206

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114206
Log:

        PR tree-optimization/24964
        * simplify-rtx.c (simplify_binary_operation_1): Add function comment.
        <MULT>: Minor clean-up.  Don't convert x*-1.0 into -x if we honor
        signaling NaNs.  Optimize -x*-x as x*x for all float modes, and
        abs(x)*abs(x) as x*x for scalar floating point modes.

        * gcc.target/i386/387-10.c: New test case.


Added:
    trunk/gcc/testsuite/gcc.target/i386/387-10.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/simplify-rtx.c
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24964


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

* [Bug tree-optimization/24964] Does not optimise abs(x)**2 to x**2
  2005-11-20 23:54 [Bug fortran/24964] New: Does not optimise abs(x)**2 to x**2 schnetter at aei dot mpg dot de
  2005-11-21  0:40 ` [Bug tree-optimization/24964] " pinskia at gcc dot gnu dot org
  2006-05-29 16:22 ` sayle at gcc dot gnu dot org
@ 2006-05-29 21:24 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-05-29 21:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2006-05-29 21:23 -------
Fixed in 4.2.0 by a RTL patch.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.2.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24964


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

end of thread, other threads:[~2006-05-29 21:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-20 23:54 [Bug fortran/24964] New: Does not optimise abs(x)**2 to x**2 schnetter at aei dot mpg dot de
2005-11-21  0:40 ` [Bug tree-optimization/24964] " pinskia at gcc dot gnu dot org
2006-05-29 16:22 ` sayle at gcc dot gnu dot org
2006-05-29 21:24 ` pinskia at gcc dot gnu dot 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).