[J3] function references and optimization

Van Snyder Van.Snyder at jpl.nasa.gov
Tue Oct 9 16:21:31 EDT 2018


On Tue, 2018-10-09 at 20:15 +0000, Bill Long via J3 wrote:
> > On Oct 9, 2018, at 2:44 PM, Robert Corbett via J3 <j3 at mailman.j3-fortran.org> wrote:
> > 
> > Van's latest e-mail led me to think
> > of a possible problem.  Suppose
> > a program contains the statement
> > function
> > 
> >      f(x) = y
> > 
> > and the assignment statement
> > 
> >      x = y - f(1.0)
> > 
> > Does the mathematical equivalence
> > rule allow the expression to be
> > replaced with 0.0?  What if f is an
> > internal procedure that returns the
> > value of y?
> > 
> > Oracle Fortran probably does the
> > first optimization at high
> > optimization levels.  Statement
> > function references are inlined,
> > so the optimization phase would
> > see the expression as y - y.
> > Oracle Fortran probably does
> > not do the optimization if f is an
> > internal procedure.  The
> > optimization could matter if the
> > value of y is infinite.
> 
> Or a NaN.  
> 
> Like similar examples, I would expect the default behavior to enable
> optimizations that improve performance at the expense of strict IEEE
> rules. But there are usually compiler options to shut down
> optimizations, such as inlining or expression simplification.   If you
> have “well behaved” data, the optimized version is usually preferred.
> Real world simulations normally don’t involve infinities or NaNs. But
> if you want to double check, you can turn off the floating point
> optimizations and see if that affects the answer. 

It shouldn't be necessary to turn off things for which the standard
makes no provision.  It should be necessary to request them, each one
explicitly.  They shouldn't be hiding behind a general level of
optimization that does several very useful but perhaps not harmful
things.

For example, I'd be happy if the processor does inter-statement register
optimization, but not if it secretly does some inter-statement
mathematically-equivalent transformations.  The standard's permission
for mathematically equivalent transformations applies only within
expressions, and only to intrinsic operations.

> Cheers,
> Bill
> 
> 
> > 
> > Robert Corbett
> 
> Bill Long                                                                       longb at cray.com
> Principal Engineer, Fortran Technical Support &   voice:  651-605-9024
> Bioinformatics Software Development                      fax:  651-605-9143
> Cray Inc./ 2131 Lindau Lane/  Suite 1000/  Bloomington, MN  55425
> 
> 




More information about the J3 mailing list