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

Wrong results in apparently simple loop

Jellby1
New Contributor I
476 Views

Consider this simple program, whose core is a relatively simple loop:

program test

implicit none
integer :: NSYM, NMIDV

NSYM = 4
NMIDV = 6
call sub(NSYM,NMIDV)

end program test

subroutine sub(NSYM,NMIDV)

implicit none
integer :: NSYM, NMIDV
integer :: NOW(2,NSYM,NMIDV), NOCSF(NSYM,NMIDV,NSYM), NCSF(NSYM)
integer :: ISYTOT, MV, ISYUP, N, ISYDWN
integer, parameter :: MUL(8,8) = reshape([1,2,3,4,5,6,7,8, &
                                          2,1,4,3,6,5,8,7, &
                                          3,4,1,2,7,8,5,6, &
                                          4,3,2,1,8,7,6,5, &
                                          5,6,7,8,1,2,3,4, &
                                          6,5,8,7,2,1,4,3, &
                                          7,8,5,6,3,4,1,2, &
                                          8,7,6,5,4,3,2,1],[8,8])

NOW(:,:,:) = reshape([4,1,0,0,0,0,2,0,0,3,4,0,4,0,0,0,4,6,0,0,0,0,2,0,1,3,0,0,0,0,2,0,0,8,2,0,1,0,0,0,1,6,0,0,0,0,0,0], &
                     [2,NSYM,NMIDV])
NCSF(:) = 0
do ISYTOT=1,NSYM
  do MV=1,NMIDV
    do ISYUP=1,NSYM
      ISYDWN = MUL(ISYTOT,ISYUP)
      N = NOW(1,ISYUP,MV)*NOW(2,ISYDWN,MV)
      NOCSF(ISYUP,MV,ISYTOT) = N
      NCSF(ISYTOT) = NCSF(ISYTOT)+N
    end do
  end do
end do
write(6,'(a,100(x,i2))') 'NCSF',NCSF

end subroutine sub

With ifx 2024.1 I get wrong results (all zeros) with -heap-arrays and -O2:

$ ifx --version
ifx (IFX) 2024.1.0 20240308
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

$ ifx -heap-arrays -O2 a.f90 && ./a.out 
NCSF  0  0  0  0
$ ifx -heap-arrays -O0 a.f90 && ./a.out 
NCSF 37 28 20 20
$ ifx -O2 a.f90 && ./a.out 
NCSF 37 28 20 20

 while the 2024.0 version works as expected:

$ /opt/intel/oneapi/compiler/2024.0/bin/ifx --version
ifx (IFX) 2024.0.2 20231213
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

$ /opt/intel/oneapi/compiler/2024.0/bin/ifx -heap-arrays -O2 a.f90 && ./a.out 
NCSF 37 28 20 20
0 Kudos
3 Replies
Ron_Green
Moderator
436 Views

@Jellby1 yes, I see this bug even in our main branch.  I think it's a change in the backend optimization phases that Intel has added to LLVM.  I am in contact with that team and am writing a bug report.  Let me see if we can find a workaround until we can get a fix.

0 Kudos
Ron_Green
Moderator
347 Views

bug ID is CMPLRLLVM-58133


0 Kudos
Devorah_H_Intel
Moderator
110 Views

I checked the status, and it is fixed in the 2025.0 release. 

0 Kudos
Reply