Optimization bug with 4.8.1
Ignacio Fernández Galván
jellby@yahoo.com
Sat Oct 26 10:43:00 GMT 2013
--------------------------------------------
On Fri, 25/10/13, Steve Kargl <sgk@troutmask.apl.washington.edu> wrote:
>> So far, I've determined the problem is not the MAX statement, but
>> rather the calculation/use of ib,ic and I get the correct value if
>> I add some write statement in the loop, but I've been unsuccessful
>> in fixing this without a write.
>
> The above suggests that you are indexing an array with an
> out-of-bounds value.
>
> Compile the code with -fcheck=all -Wall -Werror -fmax-errors=1.
Unfortunately I can't do that. This program uses its own memory management with C code, I believe, and the iWork array is declared with a very small size (8 or so), even though much larger indices are referenced.
I forgot to say that this code works (with -O2 and -O3) with other compilers, like gfortran 4.6, portland, intel... so the problem is only introduced with -O2 in 4.8.1, and in particular it can be avoided with -fno-aggressive-loop-optimizations.
To debug a bit further:
n=0
DO i=1,m
WRITE(6,*) is(3,i),is(2,i)
END DO
DO i=1,m
ib = is(3,i)
ic = is(2,i)
n=MAX(n,ib*ic)
END DO
WRITE(6,*) n
with -O0 I get:
1 3
3 2
1 2
1 2
6
but with -O2:
1 3
3 2
1 2
1 2
3
This looks like a compiler bug to me. What I want to know is if it's known (and fixed in later versions), and if there's an easy way to work around it... If it's not known, I'll try to create a self-contained test case.
Ignacio
More information about the Fortran
mailing list