Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

IFX error with complex array

g_granucci
Beginner
488 Views

This simple program gives a wrong result if compiled with ifx (version 2025.3, but also with previous versions):

program cx
  implicit none
  complex, allocatable, dimension(:,:) :: a
  integer :: i,n

  n=2
  allocate (a(-1:1,n))
  
  a(0,:)=Cmplx(0,1)
  a(-1,:)=Cmplx(4,5)
  a(1,:)=Cmplx(2,3)

  do i=1,n
    write(*,*)i,a(0,i)
  end do
end program cx
$ ./cx
           1 (4.000000,5.000000)
           2 (4.000000,5.000000)

instead of the expected result (0,1), obtained with ifort and gfortran.

3 Replies
MarcGrodent
New Contributor II
478 Views

Running the code in debug mode leads to correct results. The problem occurs in release mode, probably due to the code optimization...

I'm using version 2025.3.0

0 Kudos
Mentzer__Stuart
New Contributor I
444 Views

Good catch!  As @MarcGrodent noted it is optimization related: the bug shows up at /O2 and /O3 but not /O1.

Dumping the whole array shows that a(0,:) is treated as a(-1,:), both in the assignment and the elementwise write: the contents of a(0,:) when printing the whole array can contain (0,0) or uninitialized garbage values.

0 Kudos
Igor_V_Intel
Moderator
322 Views

This loop optimizer bug is still in the latest compiler builds. I have escalated it to be fixed.

LLVM bisect tool points to the hir-post-vec-complete-unroll optimization pass, causing the problem. Note that with O1 results are correct. Looks like a full unrolling has a bug. I also tried to disable it, but then values are set to zero, which is also not correct.

$ ifx -O2 -fno-unroll-loops test.f90

$ ./a.out

      1 (0.0000000E+00,0.0000000E+00)

      2 (0.0000000E+00,0.0000000E+00)



0 Kudos
Reply