[Patch, Fortran] PR 57160: short-circuit IF only with -ffrontend-optimize
Janus Weil
janus@gcc.gnu.org
Wed Jul 25 21:31:00 GMT 2018
Hi Thomas,
>> To expand on that point: I really don't see why a dedicated option is
>> needed. Short-circuiting of logical expressions is certainly an
>> "optimization" (which is allowed but not required by the Fortran
>> standard),
>
> If you do mean optimizations, why the quotes?
>
> And if you think this is an optimization, why did you object to
> my patch which actually used the leeway given by the
> Fortran standard?
>
> And if you don't think this is an optimization, coupling this to
> an -O option is not the right way.
first off: I clearly think that this is an optimization (I used the
quotes merely as an emphasis).
But in any case it's not about what I think, but about what the
standard says. And the standard says things like:
"It is not necessary for a processor to evaluate all of the operands
of an expression, or to evaluate entirely each
operand, if the value of the expression can be determined otherwise."
To me that sounds like omitting the evaluation of an operand (aka
"short-circuiting") is something that a compiler is allowed to do, but
not required. The main motivation for omitting the evaluation is
typically performance. So, according to my interpretation of the
standard, short-circuiting is what you would call an "optimization".
Note that this in contrast to the C/C++ case, where short-circuiting
is part of the semantics of the && and || operators, thus it's
required (not optional) and therefore not an optimization.
One of the reasons why I objected to your earlier patch was precisely
the missing possibility to disable the optimization. If this
possibility is provided, I'd actually be willing to discuss further
optimizations (provided they can guarantee for all valid code that the
results are not modified) ...
Cheers,
Janus
More information about the Fortran
mailing list