[Bug fortran/25620] Missed optimization with power

jv244 at cam dot ac dot uk gcc-bugzilla@gcc.gnu.org
Mon Sep 4 14:10:00 GMT 2006



------- Comment #9 from jv244 at cam dot ac dot uk  2006-09-04 14:10 -------
(In reply to comment #7)
> Looking at how we deal with all this, we seem to like pow() very much during
> folding, even doing the reverse transformations you suggest.  The
> transformation
> back to sqrt ( x**N ) with N being an integer could be done by
> expand_builtin_pow
> in case that computation of sqrt is cheap.  Other than that, exposing integer
> powers is only a win if theres some CSE possibility.

Despite this PR being a bit old, I'd like to add another (similar example, also
from real code) where other compilers generate much better code:

subroutine t(x)
 x=x**1.5
end subroutine t

pgf90:
# lineno: 0
        sqrtss  (%rdi), %xmm0
        mulss   (%rdi), %xmm0
        movss   %xmm0, (%rdi)

gfortran -S -O3 -ffast-math:
        movss   (%rdi), %xmm0
        movq    %rdi, %rbx
        movss   .LC0(%rip), %xmm1
        call    powf
        movss   %xmm0, (%rbx)
        popq    %rbx
        ret

trying to time this with the following fragment:
y=0.
DO i=1,10000000
 x=i
 y=y+x**1.5
ENDDO
write(6,*) y
END

pgf90 is about 10 times faster than gfortran


-- 


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



More information about the Gcc-bugs mailing list