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

Optimizer bug

mecej4
Honored Contributor III
376 Views
This is a report on an optimizer bug that is shown by the current 32-bit compiler (Update 7) for Windows, w_cprof_p_11.1.067, and the 32-bit compiler (Update 7) for Linux, l_cprof_p_11.1.073.

Starting with the longer test program reported a few days ago by Yaqi Wang, I merged and simplified his code and removed all real variables to obtain the reproducer given below.

The bug is encountered with the compiler option -O3, but not with -O2, -Ot, -Od or -fast. The correct output is -1 repeated 5 times. The incorrect output, produced with -O3, is 1 repeated 5 times.

The bug is sensitive to changes in the source code. Activating the WRITE statement on Line-54, or merging subroutines INIT and IDENT make the bug disappear. Similarly, replacing qrt(1) by qrt throughout the program makes the bug go away, as does replacing qrt(1)%a(1:qm) by qrt(1)%a on Line-55.

[fortran]MODULE DataKind
IMPLICIT NONE
INTEGER, PARAMETER :: zero = 0
INTEGER, PARAMETER :: one = 1
INTEGER, PARAMETER :: mOne = -1
END MODULE DataKind

MODULE SparseMatrix
USE DataKind
IMPLICIT NONE

TYPE CSR
INTEGER :: n
INTEGER, POINTER :: a(:) =>null()
END TYPE CSR

CONTAINS

SUBROUTINE init(a, n)
IMPLICIT NONE
TYPE(CSR) :: a
INTEGER :: n
ALLOCATE(a%a(n))
a%n = n
a%a(1:n) = zero
RETURN
END SUBROUTINE init

SUBROUTINE ident(n, a)
IMPLICIT NONE
INTEGER :: n
TYPE(CSR) :: a

CALL init(a, n)
a%a(1:n) = one
RETURN
END SUBROUTINE ident

END MODULE SparseMatrix

MODULE quad1
USE DataKind
USE SparseMatrix
IMPLICIT NONE
INTEGER, PARAMETER :: qm = 5

TYPE(CSR), SAVE :: qrt(1)

CONTAINS

SUBROUTINE quad()
IMPLICIT NONE
CALL ident(qm, qrt(1))
! write(*,'(1x,10I5)')qrt(1)%a ! <====== activate to make optimizer bug go away
qrt(1)%a(1:qm) = qrt(1)%a(1:qm) * mOne
RETURN
END SUBROUTINE quad

END MODULE quad1

program test
use quad1
implicit none

call quad()
write(*,'(1x,10I5)') qrt(1)%a
stop

end program test[/fortran]

0 Kudos
1 Reply
Kevin_D_Intel
Employee
376 Views
Greatly appreciate the time/effort to investigate and isolate this issue into a convenient reproducer, mecej4. I will test with some internal developmentcompilers and update the post when I have more information.
0 Kudos
Reply