Bug#328939: g++-4.0: do not optimize for a 'const double'
Package: g++-4.0
Version: 4.0.1-7
Severity: normal
Hello,
g++ did not optimize const double as a const, it put it in BSS.
----------------------------------->
$ cat const.cpp
//const.cpp
extern const double minute;
const double second = 1.0;
const double minute = 60.0 * second;
$ g++-3.4 -c const.cpp; nm const.o
00000000 R minute
00000008 r second
$ g++-3.4 -c -O3 const.cpp; nm const.o
00000000 R minute
$ g++-4.0 -c const.cpp; nm const.o
00000032 t _GLOBAL__I_minute
00000000 B minute
00000000 r second
00000000 t _Z41__static_initialization_and_destruction_0ii
$ g++-4.0 -c -O3 const.cpp; nm const.o
00000030 t _GLOBAL__I_minute
00000000 B minute
00000000 r second
00000000 t _Z41__static_initialization_and_destruction_0ii
<------------------------------------
another example program, it want prove this effect the speed,
in g++-3.4 foo1 and foo2 is the same, but in g++-4.0, foo2 need one more
fmull, thanks.
------------------------------------------>
$ cat opt.cpp
const double A = 3.0;
const double B = 15.0;
const double C = 5.0 * A;
double foo1(double a)
{
return 3.32 * B * a;
}
double foo2(double a)
{
return 3.32 * C * a;
}
$ g++-4.0 -c -O3 opt.cpp
$ gdb opt.o
GNU gdb 6.3-debian
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-linux"...(no debugging symbols found)
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) disassemble foo1
Dump of assembler code for function _Z4foo1d:
0x00000000 <_Z4foo1d+0>: push %ebp
0x00000001 <_Z4foo1d+1>: mov %esp,%ebp
0x00000003 <_Z4foo1d+3>: fldl 0x0
0x00000009 <B+1>: fmull 0x8(%ebp)
0x0000000c <B+4>: pop %ebp
0x0000000d <B+5>: ret
0x0000000e <B+6>: mov %esi,%esi
End of assembler dump.
(gdb) disassemble foo2
Dump of assembler code for function _Z4foo2d:
0x00000010 <_Z4foo2d+0>: push %ebp
0x00000011 <_Z4foo2d+1>: mov %esp,%ebp
0x00000013 <_Z4foo2d+3>: fldl 0x8
0x00000019 <_Z4foo2d+9>: fmull 0x0
0x0000001f <_Z4foo2d+15>: fmull 0x8(%ebp)
0x00000022 <_Z4foo2d+18>: pop %ebp
0x00000023 <_Z4foo2d+19>: ret
0x00000024 <_Z4foo2d+20>: lea 0x0(%esi),%esi
0x0000002a <_Z4foo2d+26>: lea 0x0(%edi),%edi
End of assembler dump.
$ g++-3.4 -c -O3 opt.cpp
$ gdb opt.o
GNU gdb 6.3-debian
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-linux"...(no debugging symbols found)
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) disassemble foo1
Dump of assembler code for function _Z4foo1d:
0x00000000 <_Z4foo1d+0>: push %ebp
0x00000001 <_Z4foo1d+1>: mov %esp,%ebp
0x00000003 <_Z4foo1d+3>: fldl 0x0
0x00000009 <_Z4foo1d+9>: fmull 0x8(%ebp)
0x0000000c <_Z4foo1d+12>: pop %ebp
0x0000000d <_Z4foo1d+13>: ret
0x0000000e <_Z4foo1d+14>: mov %esi,%esi
End of assembler dump.
(gdb) disassemble foo2
Dump of assembler code for function _Z4foo2d:
0x00000010 <_Z4foo2d+0>: push %ebp
0x00000011 <_Z4foo2d+1>: mov %esp,%ebp
0x00000013 <_Z4foo2d+3>: fldl 0x8
0x00000019 <_Z4foo2d+9>: fmull 0x8(%ebp)
0x0000001c <_Z4foo2d+12>: pop %ebp
0x0000001d <_Z4foo2d+13>: ret
End of assembler dump.
(gdb)
<------------------------------------------------
-- System Information:
Debian Release: testing/unstable
APT prefers unstable
APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.12-1-686-smp
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Versions of packages g++-4.0 depends on:
ii gcc-4.0 4.0.1-7 The GNU C compiler
ii gcc-4.0-base 4.0.1-7 The GNU Compiler Collection (base
ii libc6 2.3.5-6 GNU C Library: Shared libraries an
ii libstdc++6-4.0-dev 4.0.1-7 The GNU Standard C++ Library v3 (d
g++-4.0 recommends no packages.
-- no debconf information
Reply to: