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

Reply via email to