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

            Bug ID: 115711
           Summary: Fortran: extra malloc and copy with transfer
           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: ---

subroutine foo(a,b)
  complex(kind(1d0))::a
  real(kind(1d0))::b(2)

  b=transfer(a,b)
end subroutine foo

produces optimal code. But change the declarations to

  complex(kind(1d0))::a(2)
  real(kind(1d0))::b(4)

and "gfortran-14 -mavx2 -O3" calls malloc, copies a to a temporary location,
then copies into b, and calls free. Generalise to a(n) and b(2*n), passing n as
an extra integer argument, and it calls malloc, memcpy, memcpy, free.

I don't think this double copy is necessary -- just a single copy with no
temporary should suffice.

Reply via email to