public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/32239]  New: optimize power in loops
@ 2007-06-07  5:10 jv244 at cam dot ac dot uk
  2007-06-08 10:11 ` [Bug fortran/32239] " rguenth at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: jv244 at cam dot ac dot uk @ 2007-06-07  5:10 UTC (permalink / raw)
  To: gcc-bugs

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


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

end of thread, other threads:[~2007-07-02 20:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-07  5:10 [Bug fortran/32239] New: optimize power in loops jv244 at cam dot ac dot uk
2007-06-08 10:11 ` [Bug fortran/32239] " rguenth at gcc dot gnu dot org
2007-06-17  6:39 ` [Bug fortran/32239] optimize power in loops, use __builtin_powi instead of _gfortran_pow_r4_i4 jb at gcc dot gnu dot org
2007-06-17 11:40 ` patchapp at dberlin dot org
2007-06-25 19:53 ` burnus at gcc dot gnu dot org
2007-07-01 16:24 ` jb at gcc dot gnu dot org
2007-07-02 16:21 ` jb at gcc dot gnu dot org
2007-07-02 20:46 ` jb 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).