On 11/26/26 11:51, Thomas Koenig wrote:
Am 26.11.26 um 19:16 schrieb Steve Kargl:
(Yes,
I know a "Note" in the standard is not normative text.)  Once
the compiler has the "combined" expression, it can apply the
transformations from Note 2, page 163, and one gets
add4 = (a + b) + (c + d).  Your argument suggests that the
individual statements imply the existence of parentheses,

Splitting a hair really fine, parentheses are not needed, but
the end result is the same (and gfortran could implement this
handing off a PAREN_EXPR to the middle).

which
may inhibit a compiler's ability to perform optimizations.

Yes, it does (which is the point).

The "as-if" in 5.3.5 and left-to-right evaluation means one cannot distinguish if a programmer wrote

  t1 = a + b
  t2 = t1 + c
  xx = t2 + d

or

  xx = a + b + c + d

Mathematically, these are the same.  Numerically, these are
the same (as long as the compiler is inhibited from doing any
optimization such as xx = (a + b) + (c + d)).

As Fortran is a language for numerical computation, it would
seem strange for J3 to purposely inhibit a compiler from doing
an optimization here.

Likewise, consider (in double precision) the over-simplified,

  t1 = 1 / 3.0_8
  ...
  ! A bunch of FP operations that do not involve a, b, and t1
  ...
  t2 = 1 / 3.0_8 - t1
  if (t2 /= 0) then
     ...
  end if

Mathematically, a compiler should be able to set t2 = 0 without
doing any computation.  On a i387 FPU, t1 is likely flushed
from an 80-bit register with 64 bits of precision to memory
with only 53 bits precision.  If the processor reloads 1, 3.0_8,
and t1 into 80-bit FPU registers, then a - b may not equal t1.
(And, yes, I know about -ffloat-store).  I doubt anyone is going
to get upset is the compiler optimizes to t2 = 0.

--
steve


Reply via email to