Current trunk generates always a call to 
_gfortran_pow_r4_i4 for this code

SUBROUTINE T(a,b,F,n)
 REAL :: a,b,F(n)
 INTEGER :: n
 INTEGER :: i
 DO i=1,n
    a=a+F(i)*b**i
 ENDDO
END SUBROUTINE

which could, however, be transformed by the compiler (at least in -ffast-math,
but even otherwise for Fortran) in the much more efficient equivalent code

SUBROUTINE T_opt(a,b,F,n)
 REAL :: a,b,F(n)
 INTEGER :: n
 INTEGER :: i
 REAL    :: tmp

 tmp=1.0
 DO i=1,n
    tmp=tmp*b
    a=a+F(i)*tmp
 ENDDO
END SUBROUTINE

I think it is a pretty common situation (just from grepping in our code, most
non-constant integer powers we have are loop indices).


-- 
           Summary: optimize power in loops
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jv244 at cam dot ac dot uk


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

Reply via email to