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

optimizer bug?

graziano_giulianigma
1,040 Views
Have been given the following code, and it chokes with ifort 12.0 optimizer:

program test
implicit none
integer*4 k , j , ibip

do k = 1 , 10
ibip = 0
do j = 0 , 15
if (btest(k,j)) then
ibip = ibip + 1
end if
end do
write(6,*) k , ibip
end do
end program test

ifort -o test test.f
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1

ifort -O0 -o test test.f
1 1
2 1
3 2
4 1
5 2
6 2
7 3
8 1
9 2
10 2

What is happening here?
0 Kudos
9 Replies
Steven_L_Intel1
Employee
1,040 Views
Sure looks that way, doesn't it. Results are correct with -O1. I will report this to the developers.
0 Kudos
mecej4
Honored Contributor III
1,040 Views
The same bug is seen with the 12.0.2.154 compilers (IA32 and X64) on Windows 7.

The bug is not seen with the 11.1.070 compilers on Windows 7.
0 Kudos
zuch
Beginner
1,040 Views
same bug on Mac with O1 and O2 optimizations
0 Kudos
Steven_L_Intel1
Employee
1,040 Views
Yes, I see all of that as well. Issue ID is DPD200169366. Inserting a WRITE after the IF restores correct results.
0 Kudos
graziano_giulianigma
1,040 Views
As requested in the other thread relating to this bug, I was given this piece of code by a researcher at SISSA, Italy, claiming that I should always use the -fp-model precise flag with intel 12.0 (by the way, with that flag the program works: all arguments are integers, why enabling floating point precision should make the problem disappear?).

I did start a local thread with a CNR Democritos researcher about different results from a climatic model run using different versions of the ifort compiler (11.0 vs 12.0), talking about also a spurious segfault in -O3 on 12.0 on a misbehaved branch prediction, something like this:

[...]
flag = 0
namelist /mynamelist/ flag
read(infile, mynamelist) <- Flag is kept to zero value in the namelist
[...]
if (flag == 1) then
allocate(space(isamspace))
end if
[...]
if (flag == 1) then
if (space(1) == ival) then <- Segfaulting with -O3
[...]
end if
end if
[...]

Hope this helps.
0 Kudos
Steven_L_Intel1
Employee
1,040 Views
-fp-model strict turns off some optimizations which are probably at issue here.

I'm afraid we can't do anything with a paraphrase of a code segment. If you can provide a small but complete example that demonstrates the new problem, we'll be glad to take a look.
0 Kudos
Michal_Kvasnicka
Beginner
1,040 Views
Where exactly shoud be inserted WRITE after the IF?
0 Kudos
mecej4
Honored Contributor III
1,040 Views
Somewhere within the IF...ENDIF block -- after all, you are trying to trick the optimizer into giving up on optimizing the code in this vicinity, because you know that it will mess up if allowed to optimize. This is, after all, a stop-gap measure that will be abandoned after the optimizer bug is fixed.

Instead of an I/O statement, you can also try inserting a subroutine or function call, the called routine being located in a different compilation unit and IPO not active.

It is not possible to give a more precise location, since that would depend on knowing the optimization strategy in all its details, nor is it worth spending a lot of time over.
0 Kudos
Steven_L_Intel1
Employee
1,040 Views
This problem was corrected in Composer XE 2011 Update 6.
0 Kudos
Reply