This is the mail archive of the gcc@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]

Re: Optimization Question



Toon Moene just quoted something from the F2K fortran draft, in short
he claims that the standard says:


Expression              Allowable alternative form
...
X * Y - X * Z           X * ( Y - Z )
...
Expression              Nonallowable alternative form
...
X * ( Y - Z )           X * Y - X * Z


That is, in the absence of parenthesis, no standard order is assumed,
and rearrangement is allowed.

Can this be correct?  Fortran would essentially have much weaker
precedence rules (which if memory serves me correctly, ISN'T what they
taught in school).  What will happen to the tons of legacy code if
this is adopted?  To get Toon's 1st example to come out the way the
precedence rules say, you'd have to write:

			    (X*Y) - (X*Z)

which surely isn't the way most of (us) old-timers wrote code.

I can see lots of places where the rearrangement would be desirable,
and, as has been been pointed out on this thread, places where it
would be a disaster.  In the former case, it should be enabled by a
compiler flag (different than -ffast-math I suspect).

Finally, Fortran isn't the only language that would benefit from these
sorts of rearrangements (although it might be the simplest to
implement).  If gcc is going to include these (as an option) perhaps
some thought should be given to this aspect as well.

David


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