https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117805

            Bug ID: 117805
           Summary: complex type, -Ofast and IEEE-754
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mjr19 at cam dot ac.uk
  Target Milestone: ---

Gfortran avoids certain optimisations unless -Ofast is specified, as the
optimisations are not compatible with IEE-754. These include optimisations on
the complex type.

As one example, it refuses to optimise R*Z (with R real and Z complex) as
cmplx(R*real(Z),R*aimag(Z)) rather than cmplx(R,0)*Z. In contrast, the C
compiler does perform this optimisation without -Ofast, as Annex G of the C99
standard clearly permits it.

Recently the Fortran Standards Committee, J3, has clarified the application of
IEEE-754 to the complex type in Fortran. The brief summary is that it does not
apply. IEEE-754 makes no mention of the complex type, and Fortran makes no
mention of what operations should be performed on the components of a complex
number in order to evaluate a given expression. Different choices may give
different answers when faced with IEEE's "special" values. The full statement
can be found at

https://j3-fortran.org/doc/year/24/24-179.txt

Many compilers, including NAG's usually pedantic compiler, already perform
these optimisations quite freely. Now that J3 has made this statement, should
gfortran also move these optimisations to a lower optimisation level?

I think ifort, ifx and nagfor all optimise R*Z as cmplx(R*real(Z),R*aimag(Z))
at -O, and nvfortran does at -O2.

Reply via email to