This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch, fortran] PR 40628, front-end optimization pass


On Mon, Jul 19, 2010 at 06:19:32PM -0700, Jerry DeLisle wrote:
> 
> One thing I would like to suggest is can you identify a real world 
> application that benefits from this initial optimization pass?  Proof in 
> the pudding so to speak, but not strictly necessary.  I am more curious 
> then anything.
> 

See Thomas's recent c.l.f post.

module foo
  implicit none
  integer :: n = 0
contains
  integer function f(k)
    integer, intent(in) :: k
    f = k
    n = n + 1
  end function f
end module foo

program main
  use foo
  implicit none
  print *,f(3) + f(3)
  print *,n
end program main 

An optimizer can replace the 2 function calls in the print 
statement to 'print *, 2*f(3)'.  If the optimizer is really
smart, it can replace it by 'print *, 6'.  The question
then becomes what does 'print *, n' print?  The answer is
that it can print 0, 1, 2, or some other value.  The thread
has been quite interesting.

-- 
Steve


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]