Bug Report: GCC: Optimization
L. Neil Johnson
neiljohn@xmission.com
Fri May 26 03:41:00 GMT 2006
GCC BUG REPORT
OPTIMIZATION OPTIONS -O1, ETC.
25may06
This bug report describes a problem with CC optimizations -O1, -O2, or -O3.
The computational result with the options is different than without the
options. The complete set of files and the makefile necessary to reproduce
the problem are attached. A description of the problem with healthy and
anomalous output appears below. The descriptive information you requested
appears below.
I did a lot of work to find the problem (about 10 days, starting with a
PERL calling program and working backwards through a library) but not much
work to isolate it because I wanted to first determine if: a) it was a
known problem, b) has been fixed in a later release, c) you get the same
anomalous results on your platform, d) you think it's a MinGW or Windows
problem, etc.
Please email for additional information or support to the address below.
1. Software Platform:
- MinGW:
. mingw-runtime-3.8.tar.gz
. w32api-3.3.tar.gz
. binutils-2.15.91-20040904-1.tar.gz
. gcc-core-3.4.2-20040916-1.tar.gz
. gcc-g++-3.4.2-20040911-1.tar.gz
. gcc-g77-3.4.2-2004816-1.tar.gz
. mingw-utils-0.3.tar.gz
. mingw32-make-3.80.0-3.exe
. gdb-5.2.1-1.exe
. tcltk.8.4.1-1.exe
- GNU CC:
gcc version 3.4.2 (mingw-special)
- Dev-C++ 4.9.9.2
2. Complete input files:
The six files necessary to build the executable image are attached to this
bug report (hopefully neither my ISP nor yours will filter them out). This
is the complete file set. They are:
- xpredic.c (Main)
- memcof.c (function)
- predic.c (function)
- nr.h
- nrutil.h
- nrutil.c
With a minor change, they are sent as published by Cambridge University
Press [1], and they are not public domain. Neither the object files nor the
executable were included because my platform is Win32, and they would
probably have to be built on yours. The makefile I last used to build them
is included also. This should answer questions about options on the
command-line, etc.:
- Makefile.win
3. Machine and Operating System:
- IBM ThinkPad 600E
- Win98SE
If you prefer I can build the program on my Tyan S2500 PIII running W2K,
but I believe the results will be the same.
4. Configure Command
(>gcc -v)
Reading specs from C:/MINGW/BIN/../lib/gcc/mingw32/3.4.2/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as
--host=mingw32
--target=mingw32 --prefix=/mingw --enable-threads --disable-nls
--enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry
--disable-shared --enable-sjlj-exceptions --enable-libgcj
--disable-java-awt --without-x --enable-java-gc=boehm
--disable-libgcj-debug
--enable-interpreter --enable-hash-synchronization
--enable-libstdcxx-debug
Thread model: win32
5. Modifications to compiler source
None.
6. Deviations from standard procedure for installing GNU CC.
None. Downloaded and installed from tar.gz files per MinGW instructi
ons.
7. Description of anomaly:
The six files constitute a test (xpredic.c) of a function (memcof.c) which
computes linear prediction coefficients from synthetic data and another
function (predic.c) which computes 20 predictions based on a linear
combination of the coefficients and the data. The test prints out three
columns of information, the Index column, the Actual column (20 samples of
data computed from the synthetic formula), and the PREDIC column (20
samples of extrapolated data). The results on my machine, with no
optimization, are:
I Actual PREDIC
1 0.064588 0.064588
2 0.127768 0.127767
3 0.188492 0.188489
4 0.245761 0.245756
5 0.298640 0.298629
6 0.346271 0.346251
7 0.387891 0.387857
8 0.422839 0.422787
9 0.450573 0.450495
10 0.470672 0.470561
11 0.482846 0.482695
12 0.486941 0.486743
13 0.482936 0.482687
14 0.470947 0.470644
15 0.451223 0.450869
16 0.424139 0.423743
17 0.390193 0.389771
18 0.349992 0.349571
19 0.304244 0.303863
20 0.253746 0.253459
(Do not worry about the Actual column. This is simply the amplification of
a formula to compute samples for two closely space sinusoids. The PREDIC
column may vary on your machine in the last fractional digit. That's
because the routines use float types which only have 6-7 decimal digits of
precision, and because there are 3 or 4 differences which machines may
exhibit in rounding off numbers, approaching zero, etc. A one or two unit
change in the last digit is OK.)
The problem is evident when the files are compiled with command line option
-O1 (or -O2, or -O3). On my machine, the results are:
I Actual PREDIC
1 0.064588 0.064587
2 0.127768 0.127764
3 0.188492 0.188481
4 0.245761 0.245735
5 0.298640 0.298587
6 0.346271 0.346174
7 0.387891 0.387726
8 0.422839 0.422578
9 0.450573 0.450181
10 0.470672 0.470111
11 0.482846 0.482077
12 0.486941 0.485927
13 0.482936 0.481647
14 0.470947 0.469366
15 0.451223 0.449354
16 0.424139 0.422016
17 0.390193 0.387885
18 0.349992 0.347619
19 0.304244 0.301981
20 0.253746 0.251837
As you can see, beginning with small differences in the first few indices,
the error rapidly accumulates until the 20th prediction is significantly
different. According to my understanding, there should be no numerical
difference between non-optimized and optimized computations.
The CC command-line option "-fexpensive-optimizations" works transparently,
i.e. the results from xpredic.exe are identical with or without the option.
But any further optimization (-O1, -O2, -O3) produces different results.
8. Assembler output:
None.
9. References to CC source:
None.
10. Debugger information:
None.
11. References:
[1] Vetterling, William, et. al., Numerical Recipes Example Book [C], 2nd
Ed.,
Cambridge University Press, 1992, pp. 212-3.
Sincerely,
L. Neil Johnson
neiljohn@xmission.com
Att: 7
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xpredic.c
Type: application/octet-stream
Size: 862 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20060526/66cd5409/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: memcof.c
Type: application/octet-stream
Size: 954 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20060526/66cd5409/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: predic.c
Type: application/octet-stream
Size: 438 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20060526/66cd5409/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nr.h
Type: application/octet-stream
Size: 32348 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20060526/66cd5409/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nrutil.h
Type: application/octet-stream
Size: 3431 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20060526/66cd5409/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nrutil.c
Type: application/octet-stream
Size: 8276 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20060526/66cd5409/attachment-0005.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile.win
Type: application/octet-stream
Size: 1309 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20060526/66cd5409/attachment-0006.obj>
More information about the Gcc-bugs
mailing list