Bug 44897 - -flto + ipa-sra misoptimize sqlite (non-plugin only)
Summary: -flto + ipa-sra misoptimize sqlite (non-plugin only)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: mozillametabug
  Show dependency treegraph
 
Reported: 2010-07-10 02:01 UTC by Jan Hubicka
Modified: 2011-06-02 21:50 UTC (History)
6 users (show)

See Also:
Host: x86_64-linux
Target: x86_64-linux
Build: x86_64-linux
Known to work:
Known to fail:
Last reconfirmed: 2011-02-05 20:21:12


Attachments
sqlite sources (757.64 KB, application/x-bzip)
2010-07-10 02:03 UTC, Jan Hubicka
Details
sqlite shell (17.58 KB, application/x-bzip)
2010-07-10 02:04 UTC, Jan Hubicka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Hubicka 2010-07-10 02:01:56 UTC
evans:/abuild/jh/sqlite-3.6.23.1/:[0]# /abuild/jh/trunk-install/bin/gcc -fPIC -O0 -fwhopr=24  -fno-strict-aliasing -pthread -pipe  -O2    shell.c sqlite3.c -ldl  -g  ; echo "create table memos(text, priority INTEGER);" | ./a.out
Segmentation fault (core dumped)

evans:/abuild/jh/sqlite-3.6.23.1/:[139]# /abuild/jh/trunk-install/bin/gcc -fPIC -O0 -fwhopr=24  -fno-strict-aliasing -pthread -pipe  -O2    shell.c sqlite3.c -ldl  -g  -fno-ipa-sra ; echo "create table memos(text, priority INTEGER);" | ./a.out

evans:/abuild/jh/sqlite-3.6.23.1/:[139]# /abuild/jh/trunk-install/bin/gcc -fPIC -O0   -fno-strict-aliasing -pthread -pipe  -O2    shell.c sqlite3.c -ldl  -g   ; echo "create table memos(text, priority INTEGER);" | ./a.out
Comment 1 Jan Hubicka 2010-07-10 02:03:11 UTC
Created attachment 21169 [details]
sqlite sources
Comment 2 Jan Hubicka 2010-07-10 02:04:24 UTC
Created attachment 21170 [details]
sqlite shell
Comment 3 Jan Hubicka 2010-07-10 02:05:44 UTC
-O1 -fipa-sra also leads to ICE.
Comment 4 Steven Bosscher 2010-07-18 20:21:12 UTC
IPA-SRA => Martin
Comment 5 Jan Hubicka 2010-07-18 22:35:51 UTC
Subject: Re:  -fwhopr + ipa-sra misoptimize
	sqlite

> IPA-SRA => Martin
Well, the trick is that IPA-SRA is run before LTO streaming, so it means that it should not be affected
by -fwhopr at all (and linking resulting .o file w/o LTO seems to work).  So it is really combination
of those.
Comment 6 Jan Hubicka 2010-10-02 14:13:03 UTC
reconfirmed.
Comment 7 Jan Hubicka 2010-12-15 01:51:12 UTC
still fails.
Comment 8 Jan Hubicka 2011-01-10 15:01:05 UTC
jh@evans:/abuild/jh/sqlite-3.6.23.1> /abuild/jh/trunk-install/bin/gcc  -fPIC -O0 -flto=24  -fno-strict-aliasing -pthread -pipe  -O2    shell.c sqlite3.c -ldl  -g  ; echo "create table memos(text, priority INTEGER);" | ./a.out
jh@evans:/abuild/jh/sqlite-3.6.23.1> /abuild/jh/trunk-install/bin/gcc  -fPIC -O0 -flto=24  -fno-strict-aliasing -pthread -pipe  -O2    shell.c sqlite3.c -ldl  -g -flto-partition=none ; echo "create table memos(text, priority INTEGER);" | ./a.out
jh@evans:/abuild/jh/sqlite-3.6.23.1> /abuild/jh/trunk-install/bin/gcc  -fPIC -O0 -flto=24  -fno-strict-aliasing -pthread -pipe  -O2    shell.c sqlite3.c -ldl  -g -flto-partition=1to1 ; echo "create table memos(text, priority INTEGER);" | ./a.out
jh@evans:/abuild/jh/sqlite-3.6.23.1> 

So it seems solved now.  I will try if mozilla now builds w/o lto-partition=none passed to C compiler.
Comment 9 Jan Hubicka 2011-01-10 16:33:18 UTC
Hmm, sadly we still get:
 /abuild/jh/trunk-install/bin/gcc  -fPIC -O0 -flto=24  -fno-strict-aliasing -pthread -pipe  -O2    shell.c sqlite3.c -ldl  -g -flto-partition=1to1 -fno-use-linker-plugin ; echo "create table memos(text, priority INTEGER);" | ./a.out
Segmentation fault (core dumped)
Comment 10 Jan Hubicka 2011-01-10 22:10:11 UTC
It also appears with lto-partition=none with profile feedback, so it is not WHOPR only bug.
Comment 11 Markus Trippelsdorf 2011-03-10 16:07:34 UTC
In the Firefox case sqlite3.o gets compiled correctly,
it is libmozsqlite3.so that segfaults when compiled with -flto
and -fprofile-use :

gcc  -Wall -W -Wno-unused -Wpointer-arith -Wcast-align -W -pedantic -Wno-long-long -march=native -fpermissive -fno-strict-aliasing -pthread -pipe  -DNDEBUG -DTRIMMED -flto=4 -fwhole-program -fprofile-use -fprofile-correction -Wcoverage-mismatch -freorder-blocks-and-partition -O3 -fPIC -shared -Wl,-z,defs -Wl,-h,libmozsqlite3.so -o libmozsqlite3.so  sqlite3.o     -lpthread -Wl,-O1,--hash-style=gnu,--as-needed,--no-keep-memory  -fprofile-use -Wl,-rpath-link,/var/tmp/mozilla-central/moz-build-dir/dist/bin -Wl,-rpath-link,/usr/lib   -ldl

This version runs fine (no -flto):

gcc -Wall -W -Wno-unused -Wpointer-arith -Wcast-align -W -pedantic -Wno-long-long -march=native -fpermissive -fno-strict-aliasing -pthread -pipe -DNDEBUG -DTRIMMED -Wcoverage-mismatch -freorder-blocks-and-partition -fwhole-program -fprofile-use -O3 -fPIC -shared -Wl,-z,defs -Wl,-h,libmozsqlite3.so -o libmozsqlite3.so sqlite3.o -lpthread -Wl,-O1,--hash-style=gnu,--as-needed,--no-keep-memory -Wl,-rpath-link,/var/tmp/mozilla-central/moz-build-dir/dist/bin -Wl,-rpath-link,/usr/lib -ldl

And this one gives an internal compiler error (only -flto , no -fprofile-use):

gcc -Wall -W -Wno-unused -Wpointer-arith -Wcast-align -W -pedantic -Wno-long-long -march=native -fpermissive -fno-strict-aliasing -pthread -pipe -DNDEBUG -DTRIMMED -Wcoverage-mismatch -freorder-blocks-and-partition -flto -O3 -fPIC -shared -Wl,-z,defs -Wl,-h,libmozsqlite3.so -o libmozsqlite3.so sqlite3.o -lpthread -Wl,-O1,--hash-style=gnu,--as-needed,--no-keep-memory -Wl,-rpath-link,/var/tmp/mozilla-central/moz-build-dir/dist/bin -Wl,-rpath-link,/usr/lib -ldl
lto1: internal compiler error: Floating point exception
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper: /usr/x86_64-pc-linux-gnu/gcc-bin/4.6.0/gcc returned 1 exit status
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/../../../../x86_64-pc-linux-gnu/bin/ld: fatal error: lto-wrapper failed
collect2: ld returned 1 exit status

(All these commands should be run from: 
./mozilla-central/moz-build-dir/db/sqlite3/src
One can copy the resulting libmozsqlite3.so directly into 
/usr/lib/firefox-4.0b13pre and try to start Firefox, to check
if it's OK or not)
Comment 12 Jan Hubicka 2011-03-10 16:26:01 UTC
> gcc -Wall -W -Wno-unused -Wpointer-arith -Wcast-align -W -pedantic
> -Wno-long-long -march=native -fpermissive -fno-strict-aliasing -pthread -pipe
> -DNDEBUG -DTRIMMED -Wcoverage-mismatch -freorder-blocks-and-partition -flto -O3
> -fPIC -shared -Wl,-z,defs -Wl,-h,libmozsqlite3.so -o libmozsqlite3.so sqlite3.o
> -lpthread -Wl,-O1,--hash-style=gnu,--as-needed,--no-keep-memory
> -Wl,-rpath-link,/var/tmp/mozilla-central/moz-build-dir/dist/bin
> -Wl,-rpath-link,/usr/lib -ldl
> lto1: internal compiler error: Floating point exception

This should be easy to fix. Having backtrace would save me from some burden trying to reproduce it ;)

Honza
Comment 13 Markus Trippelsdorf 2011-03-10 18:39:21 UTC
Here's what I got:
(gdb) set follow-fork-mode child
(gdb) run -plugin /usr/libexec/gcc/x86_64-pc-linux-gnu/4.6.0/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.6.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccZJwWXj.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -flto --eh-frame-hdr -m elf_x86_64 -shared -o libmozsqlite3.so /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/../../../../lib64/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/crtbeginS.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/../../.. -z defs -h libmozsqlite3.so sqlite3.o -lpthread --hash-style=gnu -rpath-link /var/tmp/mozilla-central/moz-build-dir/dist/bin -rpath-link /usr/lib -ldl -lgcc --as-needed -lgcc_s --no-as-needed -lpthread -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/crtendS.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/../../../../lib64/crtn.o
Starting program: /usr/libexec/gcc/x86_64-pc-linux-gnu/4.6.0/collect2 -plugin /usr/libexec/gcc/x86_64-pc-linux-gnu/4.6.0/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.6.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccZJwWXj.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -flto --eh-frame-hdr -m elf_x86_64 -shared -o libmozsqlite3.so /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/../../../../lib64/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/crtbeginS.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/../../.. -z defs -h libmozsqlite3.so sqlite3.o -lpthread --hash-style=gnu -rpath-link /var/tmp/mozilla-central/moz-build-dir/dist/bin -rpath-link /usr/lib -ldl -lgcc --as-needed -lgcc_s --no-as-needed -lpthread -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/crtendS.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/../../../../lib64/crtn.o
[New process 16093]
process 16093 is executing new program: /usr/x86_64-pc-linux-gnu/binutils-bin/2.21.51.0.7/ld
[New process 16102]
process 16102 is executing new program: /usr/libexec/gcc/x86_64-pc-linux-gnu/4.6.0/lto-wrapper
[New process 16103]
process 16103 is executing new program: /usr/x86_64-pc-linux-gnu/gcc-bin/4.6.0/gcc
[New process 16104]
process 16104 is executing new program: /usr/libexec/gcc/x86_64-pc-linux-gnu/4.6.0/lto1

Program received signal SIGFPE, Arithmetic exception.
[Switching to process 16104]
0x0000000000862ca7 in ?? ()
(gdb) bt
#0  0x0000000000862ca7 in ?? ()
#1  0x000000000066f176 in execute_one_pass(opt_pass*) ()
#2  0x000000000066fa52 in execute_ipa_pass_list(opt_pass*) ()
#3  0x00000000004f284e in lto_main() ()
#4  0x00000000006fc247 in toplev_main(int, char**) ()
#5  0x00007ffff6d28f8d in __libc_start_main () from /lib/libc.so.6
#6  0x00000000004cd9f9 in _start ()
(gdb)
Comment 14 Markus Trippelsdorf 2011-03-10 19:13:55 UTC
And the same with debugging symbols:

Program received signal SIGFPE, Arithmetic exception.
[Switching to process 5046]
0x000000000086d41c in cgraph_decide_recursive_inlining (new_edges=0x7fffffffd750, node=0x7ffff65dbb00) at ../../gcc/gcc/ipa-inline.c:906
906               if (curr->count * 100 / node->count < probability)
(gdb) bt
#0  0x000000000086d41c in cgraph_decide_recursive_inlining (new_edges=0x7fffffffd750, node=0x7ffff65dbb00) at ../../gcc/gcc/ipa-inline.c:906
#1  cgraph_decide_inlining_of_small_functions () at ../../gcc/gcc/ipa-inline.c:1193
#2  cgraph_decide_inlining () at ../../gcc/gcc/ipa-inline.c:1479
#3  0x00000000006571e9 in execute_one_pass (pass=0x102ee00) at ../../gcc/gcc/passes.c:1556
#4  0x000000000065787a in execute_ipa_pass_list (pass=0x102ee00) at ../../gcc/gcc/passes.c:1923
#5  0x00000000004c152f in do_whole_program_analysis () at ../../gcc/gcc/lto/lto.c:2350
#6  lto_main () at ../../gcc/gcc/lto/lto.c:2462
#7  0x00000000006e7510 in compile_file () at ../../gcc/gcc/toplev.c:579
#8  do_compile () at ../../gcc/gcc/toplev.c:1900
#9  toplev_main (argc=40, argv=0x11679c0) at ../../gcc/gcc/toplev.c:1963
#10 0x00007ffff6d28f8d in __libc_start_main () from /lib/libc.so.6
#11 0x00000000004a9979 in _start () at ../sysdeps/x86_64/elf/start.S:113
(gdb)
Comment 15 Jan Hubicka 2011-04-03 09:00:04 UTC
Sorry, forgot about the division by zero issue. Testing patch.
Comment 16 vincenzo Innocente 2011-05-19 08:12:20 UTC
I'm getting a whole bunch of
lto1: internal compiler error: Floating point exception
using
g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.6.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure -enable-gold=yes --enable-lto --with-fpmath=avx --with-build-config=bootstrap-lto --with-gmp-lib=/usr/local/lib64 --with-mpfr-lib=/usr/local/lib64 -with-mpc-lib=/usr/local/lib64
Thread model: posix
gcc version 4.6.1 20110513 (prerelease) (GCC) 

before submitting a new bug report I would like to know if the patch by Honza quoted below is already in it or still pending
Comment 17 Jan Hubicka 2011-05-19 08:56:37 UTC
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44897
> 
> vincenzo Innocente <vincenzo.innocente at cern dot ch> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |vincenzo.innocente at cern
>                    |                            |dot ch
> 
> --- Comment #16 from vincenzo Innocente <vincenzo.innocente at cern dot ch> 2011-05-19 08:12:20 UTC ---
> I'm getting a whole bunch of
> lto1: internal compiler error: Floating point exception
> using
> g++ -v
> Using built-in specs.
> COLLECT_GCC=g++
> COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.6.1/lto-wrapper
> Target: x86_64-unknown-linux-gnu
> Configured with: ./configure -enable-gold=yes --enable-lto --with-fpmath=avx
> --with-build-config=bootstrap-lto --with-gmp-lib=/usr/local/lib64
> --with-mpfr-lib=/usr/local/lib64 -with-mpc-lib=/usr/local/lib64
> Thread model: posix
> gcc version 4.6.1 20110513 (prerelease) (GCC) 
> 
> before submitting a new bug report I would like to know if the patch by Honza
> quoted below is already in it or still pending

It is in mainline, I should backport it to 4.6.1. Will try to do it today or tomorrow.

Honza
> 
> -- 
> Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You reported the bug.
Comment 18 Jan Hubicka 2011-05-25 11:36:53 UTC
Author: hubicka
Date: Wed May 25 11:36:49 2011
New Revision: 174183

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174183
Log:

	PR tree-optimization/44897 
	* ipa-inline.c (cgraph_decide_recursive_inlining): Do not divide
	by zero for insane profiles.

Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/ipa-inline.c
Comment 19 Jan Hubicka 2011-05-25 11:44:17 UTC
OK, division by 0 should be fixed both on mainline and 4.6 branch.  I think the wrong code issue might be the corruption of jump tables, but will need to get past firewall to double check unless Martin beats me.  It is his bug after all ;)
Comment 20 Jan Hubicka 2011-06-02 01:12:12 UTC
The problem as confirmed in Comment 9 no longer reproduce on mainline. So problem is either fixed or went latent.  I am going to try 4.6.
Comment 21 Markus Trippelsdorf 2011-06-02 16:10:40 UTC
(In reply to comment #20)
> The problem as confirmed in Comment 9 no longer reproduce on mainline. So
> problem is either fixed or went latent.  I am going to try 4.6.

Confirmed on mainline. With "-flto -fprofile-use" libmozsqlite3.so no longer
segfaults. Must have been a recent change. It still segfaulted ~ a week ago.
Comment 22 Jan Hubicka 2011-06-02 21:50:54 UTC
Thanks for confirmation. My best bet is:
2011-05-29  Richard Guenther  <rguenther@suse.de>

        PR tree-optimization/49217
        * ipa-pure-const.c (propagate_pure_const): Fix typos.

this bug could've caused symptoms seen here.  Closing the PR then.