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

--- Comment #6 from mjr19 at cam dot ac.uk ---
A further comment to aid others reading this report. It is not just unnecessary
brackets which used to prevent vectorisation, but also necessary ones.

subroutine foo(a,b,c,n)
  complex (kind(1d0)) :: a(*),b,c
  integer :: i,n

  do i=1,n
     a(i)=(a(i)+b)*c
  enddo
end subroutine foo

does not vectorise with gfortran-14, but does with gfortran-15.0-20240623.

The performance increase in loops making extensive use of complex variables can
therefore be quite significant -- fifty percent or more.

The almost-equivalent C code of

void foo(_Complex double *a, _Complex double b, _Complex double c, int n){
  int i;
  for(i=0;i<n;i++) a[i]=(a[i]+b)*c;
}

does vectorise with gcc-14 (and earlier versions).

I still find gfortran to be slower than ifort for code using complex variables,
as ifort is better at flipping alternate signs in a vector and generally
alternating nops in a vector, see PR 114324 and PR 114767, but this is a very
welcome improvement. Many thanks.

Reply via email to