Bug 19340 - Compilation SEGFAULTs with -O1 -fschedule-insns2 -fsched2-use-traces on an x86 architecture.
Summary: Compilation SEGFAULTs with -O1 -fschedule-insns2 -fsched2-use-traces on an x8...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.0.0
: P2 minor
Target Milestone: 3.4.5
Assignee: Uroš Bizjak
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-on-valid-code, patch
: 15439 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-01-08 23:42 UTC by Martin Drab
Modified: 2005-11-11 08:20 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 4.0.3 4.1.0 3.4.5
Known to fail: 3.4.0
Last reconfirmed: 2005-11-07 13:20:12


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Drab 2005-01-08 23:42:54 UTC
The following test code

-- test.c -------------------------------------
extern double f (double x);

double g (int a)
{
        int b, c, d, e = 0;
        double h;

        for (d = 0; d < a; d++)
                for (c = 0; c < a; c++)
                        b = 1;

        h = (double) e / (double) a;

        if (h)
        {
                h = 1.0 / h;
                h = f(h);
        }
        else
                h = 1.0;

        return h;
}
-----------------------------------------------

when compiled with

-----------------------------------------------
gcc -S -O1 -fschedule-insns2 -fsched2-use-traces test.c -o test.s
-----------------------------------------------

using the following GCC

-----------------------------------------------
$ gcc -v
Using built-in specs.
Configured with: ../../../gcc-CVS-20050107/gcc-CVS-20050107/configure
--host=i686-pc-linux-gnu --prefix=/usr/local/opt/gcc-4.0
--exec-prefix=/usr/local/opt/gcc-4.0 --sysconfdir=/etc
--libdir=/usr/local/opt/gcc-4.0/lib --libexecdir=/usr/local/opt/gcc-4.0/libexec
--sharedstatedir=/var --localstatedir=/var --program-suffix=-4.0
--with-x-includes=/usr/X11R6/include --with-x-libraries=/usr/X11R6/lib
--enable-shared --enable-static --with-gnu-as --with-gnu-ld --with-stabs
--enable-threads=posix --enable-version-specific-runtime-libs --disable-coverage
--enable-gather-detailed-mem-stats --disable-libgcj --disable-checking
--enable-multilib --with-x --enable-cmath --enable-libstdcxx-debug
--enable-fast-character --enable-hash-synchronization --with-system-zlib
--with-libbanshee --with-demangler-in-ld --with-arch=athlon-xp --enable-libada
--enable-languages=c,c++,f95,objc,ada
Thread model: posix
gcc version 4.0.0 20050107 (experimental)
$
-----------------------------------------------

(i.e., native gcc for the x86 architecture) SEGFAULTs in a following way:

-----------------------------------------------
$ gcc -v -S -O1 -fschedule-insns2 -fsched2-use-traces test.c -o test.s
Using built-in specs.
Configured with: ../../../gcc-CVS-20050107/gcc-CVS-20050107/configure
--host=i686-pc-linux-gnu --prefix=/usr/local/opt/gcc-4.0
--exec-prefix=/usr/local/opt/gcc-4.0 --sysconfdir=/etc
--libdir=/usr/local/opt/gcc-4.0/lib --libexecdir=/usr/local/opt/gcc-4.0/libexec
--sharedstatedir=/var --localstatedir=/var --program-suffix=-4.0
--with-x-includes=/usr/X11R6/include --with-x-libraries=/usr/X11R6/lib
--enable-shared --enable-static --with-gnu-as --with-gnu-ld --with-stabs
--enable-threads=posix --enable-version-specific-runtime-libs --disable-coverage
--enable-gather-detailed-mem-stats --disable-libgcj --disable-checking
--enable-multilib --with-x --enable-cmath --enable-libstdcxx-debug
--enable-fast-character --enable-hash-synchronization --with-system-zlib
--with-libbanshee --with-demangler-in-ld --with-arch=athlon-xp --enable-libada
--enable-languages=c,c++,f95,objc,ada
Thread model: posix
gcc version 4.0.0 20050107 (experimental)
 /usr/local/opt/gcc-4.0/libexec/gcc/i786-pc-linux-gnu/4.0.0/cc1 -quiet -v
-iprefix
/usr/local/opt/gcc-4.0/lib/gcc/i786-pc-linux-gnu/4.0.0/i786-pc-linux-gnu/4.0.0/
test.c -quiet -dumpbase test.c -march=athlon-xp -auxbase-strip test.s -O1
-version -fschedule-insns2 -fsched2-use-traces -o test.s
ignoring nonexistent directory
"/usr/local/opt/gcc-4.0/lib/gcc/i786-pc-linux-gnu/4.0.0/i786-pc-linux-gnu/4.0.0/include"
ignoring nonexistent directory
"/usr/local/opt/gcc-4.0/lib/gcc/i786-pc-linux-gnu/4.0.0/i786-pc-linux-gnu/4.0.0/../../../../i786-pc-linux-gnu/include"
ignoring nonexistent directory
"/usr/local/opt/gcc-4.0/lib/gcc/i786-pc-linux-gnu/4.0.0/../../../../i786-pc-linux-gnu/include"
ignoring duplicate directory "/usr/local/include"
  as it is a non-system directory that duplicates a system directory
ignoring duplicate directory
"/usr/local/opt/gcc-4.0/lib/gcc/i786-pc-linux-gnu/4.0.0/include"
  as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/local/opt/gcc-4.0/include
 /usr/local/opt/gcc-4.0/lib/gcc/i786-pc-linux-gnu/4.0.0/include
 /usr/include
End of search list.
GNU C version 4.0.0 20050107 (experimental) (i786-pc-linux-gnu)
        compiled by GNU C version 4.0.0 20050107 (experimental).
GGC heuristics: --param ggc-min-expand=90 --param ggc-min-heapsize=113230
test.c: In function 'g':
test.c:23: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
$
-----------------------------------------------

Following command lines (at least from those that I was testing) also segfault
the same way (don't know which ones are related and which ones could be
different bug ;):

-----------------------------------------------
gcc -S -O1 -fregmove -fschedule-insns2 -fsched2-use-traces -freorder-blocks
-freorder-blocks-and-partition test.c -o test.s
gcc -S -O2 -fregmove -fschedule-insns2 -fsched2-use-traces -freorder-blocks
-freorder-blocks-and-partition test.c -o test.s
gcc -S -O3 -fregmove -fschedule-insns2 -fsched2-use-traces -freorder-blocks
-freorder-blocks-and-partition test.c -o test.s
gcc -S -O1 -fregmove -fschedule-insns2 -fsched2-use-traces test.c -o test.s
gcc -S -O1 -fschedule-insns2 -fsched2-use-traces -freorder-blocks
-freorder-blocks-and-partition test.c -o test.s
gcc -S -O1 -fschedule-insns2 -fsched2-use-traces -freorder-blocks-and-partition
test.c -o test.s
-----------------------------------------------

Following command lines pass without a problem:

-----------------------------------------------
gcc -S -O1 -fregmove -fschedule-insns2 -fsched2-use-traces -freorder-blocks
test.c -o test.s
gcc -S -O1 -fregmove -fschedule-insns2 -fsched2-use-traces
-freorder-blocks-and-partition test.c -o test.s
gcc -S -O1 -fregmove -fschedule-insns2 -freorder-blocks
-freorder-blocks-and-partition test.c -o test.s
gcc -S -O1 -fregmove -fschedule-insns2 -freorder-blocks-and-partition test.c -o
test.s
gcc -S -O1 -fregmove -fschedule-insns2 test.c -o test.s
gcc -S -O1 -fregmove -fsched2-use-traces -freorder-blocks
-freorder-blocks-and-partition test.c -o test.s
gcc -S -O1 -fregmove -fsched2-use-traces -freorder-blocks-and-partition test.c
-o test.s
gcc -S -O1 -fregmove -fsched2-use-traces test.c -o test.s
-----------------------------------------------

(I hope it can help). However ALL of the above mentioned cases pass without a
problem on the following native x86_64 arch (same sources). compiler:

----------------------------------------------
$ gcc -v
Using built-in specs.
Configured with: ../../../gcc-CVS-20050107/gcc-CVS-20050107/configure
--host=x86_64-pc-linux-gnu --prefix=/usr/local/opt/gcc-4.0
--exec-prefix=/usr/local/opt/gcc-4.0 --sysconfdir=/etc
--libdir=/usr/local/opt/gcc-4.0/lib64
--libexecdir=/usr/local/opt/gcc-4.0/libexec64 --sharedstatedir=/var
--localstatedir=/var --program-suffix=-4.0 --with-x-includes=/usr/X11R6/include
--with-x-libraries=/usr/X11R6/lib64 --enable-shared --enable-static
--with-gnu-as --with-gnu-ld --with-stabs --enable-threads=posix
--enable-version-specific-runtime-libs --disable-coverage
--enable-gather-detailed-mem-stats --disable-libgcj --disable-checking
--enable-multilib --with-x --enable-cmath --enable-libstdcxx-debug
--enable-fast-character --enable-hash-synchronization --with-system-zlib
--with-libbanshee --with-demangler-in-ld --with-arch=athlon64 --disable-libada
--enable-languages=c,c++,f95,objc
Thread model: posix
gcc version 4.0.0 20050107 (experimental)
----------------------------------------------

Also removal of any part of the code within the g() function makes the code to
pass all the mentioned compilation command lines.

Here is the backtrace of the first mentioned command line:

----------------------------------------------
#0  stack_regs_mentioned_p (pat=0x9e8b3b5d) at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/reg-stack.c:279
#1  0x08297501 in stack_regs_mentioned_p (pat=Variable "pat" is not available.)
at ../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/reg-stack.c:293
#2  0x082974df in stack_regs_mentioned_p (pat=Variable "pat" is not available.)
at ../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/reg-stack.c:290
#3  0x08297598 in stack_regs_mentioned (insn=0xb7e0e258) at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/reg-stack.c:325
#4  0x08298195 in emit_swap_insn (insn=0xb7dffc64, regstack=Variable "regstack"
is not available.) at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/reg-stack.c:931
#5  0x08298d63 in change_stack (insn=0xb7dffc64, old=0xbfffe544, new=0x852d090,
where=EMIT_BEFORE) at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/reg-stack.c:2523
#6  0x0829a9bb in compensate_edge (e=0xb7df2488, file=0x0) at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/reg-stack.c:2780
#7  0x0829b103 in convert_regs_2 (file=0x0, block=Variable "block" is not
available.) at ../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/reg-stack.c:2985
#8  0x0829b6f3 in reg_to_stack (file=0x0) at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/reg-stack.c:3082
#9  0x082ede67 in rest_of_compilation () at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/passes.c:381
#10 0x0809f974 in execute_pass_list (pass=0x843fc20) at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/tree-optimize.c:526
#11 0x0809fc12 in tree_rest_of_compilation (fndecl=0xb7df1288) at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/tree-optimize.c:662
#12 0x0805ab96 in c_expand_body (fndecl=0xb7df1288) at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/c-decl.c:6424
#13 0x08311a5c in cgraph_expand_function (node=0xb7df1948) at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/cgraphunit.c:822
#14 0x08311b00 in cgraph_assemble_pending_functions () at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/cgraphunit.c:305
#15 0x08312058 in cgraph_finalize_function (decl=0xb7df1288, nested=0 '\0') at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/cgraphunit.c:388
#16 0x0805ae5b in finish_function () at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/c-decl.c:6396
#17 0x0804e497 in yyparse () at c-parse.y:401
#18 0x0804fc28 in c_parse_file () at c-parse.y:2936
#19 0x08083615 in c_common_parse_file (set_yydebug=-1635042467) at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/c-opts.c:1092
#20 0x082d3ef5 in toplev_main (argc=2659924829, argv=0xbffff144) at
../../../../gcc-CVS-20050107/gcc-CVS-20050107/gcc/toplev.c:996
#21 0xb7eb8ea0 in __libc_start_main (main=0x8091120 <main>, argc=16,
ubp_av=0xbffff144, init=0x83a3cc0 <__libc_csu_init>, fini=0xbffff0d0,
rtld_fini=0xbffff144, stack_end=0xbffff13c)
               at ../sysdeps/generic/libc-start.c:209
#22 0x08049aa1 in _start () at ../sysdeps/i386/elf/start.S:102
----------------------------------------------
Comment 1 Andrew Pinski 2005-01-08 23:59:22 UTC
Confirmed but note this is not a regression, -fsched2-use-traces is a new option in 3.4.0 and above 
and it has been failing since -fsched2-use-traces was added.
Comment 2 Martin Drab 2005-08-18 01:56:19 UTC
This bug seems to be fixed in gcc version 4.1.0 20050817 (experimental),
however it still seems to remain in gcc version 4.0.2 20050804 (prerelease).
Comment 3 Andrew Pinski 2005-11-04 15:32:09 UTC
Fails on the mainline for me.
t.c: In function ‘g’:
t.c:23: internal compiler error: in move_for_stack_reg, at reg-stack.c:1062
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Comment 4 Uroš Bizjak 2005-11-07 13:20:12 UTC
Patch here: http://gcc.gnu.org/ml/gcc-patches/2005-11/msg00438.html
Comment 5 uros 2005-11-08 06:21:54 UTC
Subject: Bug 19340

Author: uros
Date: Tue Nov  8 06:21:51 2005
New Revision: 106632

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106632
Log:
	PR target/19340
	* reg-stack.c (reg_to_stack): Update register liveness also
	for flag_sched2_use_traces.

testsuite/

	PR target/19340
	* gcc.dg/pr19340.c: New test.


Added:
    trunk/gcc/testsuite/gcc.dg/pr19340.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/reg-stack.c
    trunk/gcc/testsuite/ChangeLog

Comment 6 uros 2005-11-08 07:59:06 UTC
Subject: Bug 19340

Author: uros
Date: Tue Nov  8 07:58:51 2005
New Revision: 106633

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106633
Log:
	PR target/19340
	* reg-stack.c (reg_to_stack): Update register liveness also
	for flag_sched2_use_traces.

	PR target/24315
	* config/i386/i386.md (*pushdi2_rex64 splitter)
	(*movdi_1_rex64 splitter, *ashldi3_1 splitter)
	(*ashrdi3_1 splitter, *lshrdi3_1 splitter): Delay splitting after
	flow2 pass only when (optimize > 0 && flag_peephole2).

testsuite/

	PR target/19340
	* gcc.dg/pr19340.c: New test.

	PR target/24315
	* gcc.target/i386/pr24315.c: New test.


Added:
    branches/gcc-4_0-branch/gcc/testsuite/gcc.dg/pr19340.c
    branches/gcc-4_0-branch/gcc/testsuite/gcc.target/i386/pr24315.c
Modified:
    branches/gcc-4_0-branch/gcc/ChangeLog
    branches/gcc-4_0-branch/gcc/config/i386/i386.md
    branches/gcc-4_0-branch/gcc/reg-stack.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog

Comment 7 Uroš Bizjak 2005-11-08 08:12:21 UTC
Fixed on mainline and 4.0 branch.
Comment 8 uros 2005-11-10 07:27:53 UTC
Subject: Bug 19340

Author: uros
Date: Thu Nov 10 07:27:47 2005
New Revision: 106728

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106728
Log:
        PR target/24315
        * config/i386/i386.md (*pushdi2_rex64 splitter)
        (*movdi_1_rex64 splitter): Delay splitting after
        flow2 pass only when (optimize > 0 && flag_peephole2).

	PR target/19340
	* reg-stack.c (reg_to_stack): Update register liveness also
	for flag_sched2_use_traces.

testsuite/

        PR target/24315
        * gcc.dg/pr24315.c: New test.

        PR target/19340
        * gcc.dg/pr19340.c: New test.


Added:
    branches/gcc-3_4-branch/gcc/testsuite/gcc.dg/pr19340.c
      - copied unchanged from r106632, trunk/gcc/testsuite/gcc.dg/pr19340.c
    branches/gcc-3_4-branch/gcc/testsuite/gcc.dg/pr24315.c
Modified:
    branches/gcc-3_4-branch/gcc/ChangeLog
    branches/gcc-3_4-branch/gcc/config/i386/i386.md
    branches/gcc-3_4-branch/gcc/reg-stack.c
    branches/gcc-3_4-branch/gcc/testsuite/ChangeLog

Comment 9 Uroš Bizjak 2005-11-10 07:33:57 UTC
Fixed on 3.4 branch.
Comment 10 Uroš Bizjak 2005-11-11 08:20:16 UTC
*** Bug 15439 has been marked as a duplicate of this bug. ***