Bug 21716 - [3.4/4.0/4.1 Regression] ICE in reg-stack.c's swap_rtx_condition
[3.4/4.0/4.1 Regression] ICE in reg-stack.c's swap_rtx_condition
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: target
3.4.4
: P2 normal
: 3.4.5
Assigned To: Not yet assigned to anyone
http://gcc.gnu.org/ml/gcc-patches/200...
: ice-on-valid-code, patch
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-05-23 08:58 UTC by Jakub Jelinek
Modified: 2005-07-11 16:05 UTC (History)
2 users (show)

See Also:
Host:
Target: i386-linux
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-05-23 13:52:52


Attachments
pr21716.c (68.73 KB, text/plain)
2005-05-23 09:02 UTC, Jakub Jelinek
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2005-05-23 08:58:44 UTC
Attached testcase ICEs at -m32 -march=i386 -O2 -ffast-math in swap_rtx_condition.
Cross jumping there merges testqi_ext_0/jcc_1 from 2 different BB's, but keeps
the %ax setters (cmpfp_2_df_1) in the original blocks.
(insn:HI 2037 4155 2038 55 (set (reg:HI 0 ax [783])
        (unspec:HI [
                (compare:CCFP (reg/v:DF 10 st(2) [orig:354 cf0d2 ] [354])
                    (reg:DF 12 st(4)))
            ] 24)) 22 {*cmpfp_2_df_1} (insn_list 4399 (insn_list 4400 (nil)))
    (expr_list:REG_DEAD (reg:DF 12 st(4))
        (nil)))

(note:HI 2038 2037 4525 55 NOTE_INSN_DELETED)
;; End of basic block 55, registers live:
 0 [ax] 3 [bx] 4 [si] 5 [di] 6 [bp] 7 [sp] 10 [st(2)] 11 [st(3)] 13 [st(5)] 14
[st(6)] 15 [st(7)] 16 [argp] 20 [frame]

;; Start of basic block 56, registers live: 0 [ax] 3 [bx] 4 [si] 5 [di] 6 [bp] 7
[sp] 10 [st(2)] 11 [st(3)] 13 [st(5)] 14 [st(6)] 15 [st(7)] 16 [argp] 20 [frame]
(code_label 4525 2038 4523 56 173 "" [1 uses])

(note 4523 4525 2448 56 [bb 56] NOTE_INSN_BASIC_BLOCK)

(note:HI 2448 4523 2449 56 NOTE_INSN_DELETED)

(note:HI 2449 2448 2450 56 NOTE_INSN_DELETED)

(note:HI 2450 2449 4359 56 NOTE_INSN_DELETED)

(insn 4359 2450 2453 56 (set (reg:CCZ 17 flags)
        (compare:CCZ (and:SI (zero_extract:SI (reg:SI 0 ax [834])
                    (const_int 8 [0x8])
                    (const_int 8 [0x8]))
                (const_int 1 [0x1]))
            (const_int 0 [0x0]))) 278 {*testqi_ext_0} (nil)
    (expr_list:REG_DEAD (reg:SI 0 ax [834])
        (nil)))

(jump_insn:HI 2453 4359 4454 56 (set (pc)
        (if_then_else (eq (reg:CCZ 17 flags)
                (const_int 0 [0x0]))
            (label_ref 1835)
            (pc))) 494 {*jcc_1} (insn_list 4359 (nil))
    (expr_list:REG_DEAD (reg:CCZ 17 flags)
        (expr_list:REG_BR_PROB (const_int 8448 [0x2100])
            (nil))))

When swap_rtx_condition is called on insn 2037, it doesn't find the %ax user
in the same BB, but as the last instruction in the BB is not INSN_P(), it crashes
when trying to dereference it's PATTERN.
Comment 1 Jakub Jelinek 2005-05-23 09:02:21 UTC
Created attachment 8950 [details]
pr21716.c

Testcase (too large though).
Comment 2 Andrew Pinski 2005-05-23 13:52:52 UTC
Confirmed.
Comment 3 Volker Reichelt 2005-05-23 16:39:07 UTC
Here's a reduced testcase that might be appropriate for the testsuite:

======================================================================
/* PR target/21716 */
/* { dg-do compile } */
/* { dg-options "-march=i386 -m32 -O2 -ffast-math" { i?86-*-* } } */

double atan (double);

void foo()
{
   double x, y;

   do
     {
       goto L2;
     L1:
       if (x) goto L1;
     L2:
       x += atan (y);
       goto L1;
     }
   while (1);
}
======================================================================

For me the original testcase and the reduced one only crash with the
3.4 branch on a native i686-pc-linux-gnu box.
Comment 4 CVS Commits 2005-05-26 08:07:52 UTC
Subject: Bug 21716

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jakub@gcc.gnu.org	2005-05-26 08:07:36

Modified files:
	gcc            : ChangeLog reg-stack.c 

Log message:
	PR target/21716
	* reg-stack.c (swap_rtx_condition): Don't crash if %ax user was not
	found in the basic block and last insn in the basic block is not
	INSN_P.  Remove explicit unspec numbers that are no longer valid
	from comments.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8907&r2=2.8908
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/reg-stack.c.diff?cvsroot=gcc&r1=1.177&r2=1.178

Comment 5 CVS Commits 2005-05-26 08:55:24 UTC
Subject: Bug 21716

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	jakub@gcc.gnu.org	2005-05-26 08:55:07

Modified files:
	gcc            : ChangeLog reg-stack.c 

Log message:
	PR target/21716
	* reg-stack.c (swap_rtx_condition): Don't crash if %ax user was not
	found in the basic block and last insn in the basic block is not
	INSN_P.  Remove explicit unspec numbers that are no longer valid
	from comments.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.263&r2=2.7592.2.264
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/reg-stack.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.171&r2=1.171.10.1

Comment 6 CVS Commits 2005-05-26 09:05:13 UTC
Subject: Bug 21716

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	jakub@gcc.gnu.org	2005-05-26 09:05:05

Modified files:
	gcc            : ChangeLog reg-stack.c 

Log message:
	PR target/21716
	* reg-stack.c (swap_rtx_condition): Don't crash if %ax user was not
	found in the basic block and last insn in the basic block is not
	INSN_P.  Remove explicit unspec numbers that are no longer valid
	from comments.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.871&r2=2.2326.2.872
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/reg-stack.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.140.4.2&r2=1.140.4.3

Comment 7 Andrew Pinski 2005-05-26 12:05:55 UTC
Fixed.
Comment 8 Volker Reichelt 2005-06-02 16:05:51 UTC
The testcase from comment #3 still crashes on the 3.4 branch:

ePR21716.c: In function `foo':
ePR21716.c:21: internal compiler error: in subst_stack_regs_pat, at reg-stack.c:1445
Please submit a full bug report, [etc.]
Comment 9 Jakub Jelinek 2005-06-02 16:07:48 UTC
Yeah, it is a different bug, one that does not exhibit on the original testcase.
Therefore IMHO a separate PR is needed...
Comment 10 Andrew Pinski 2005-06-02 19:00:24 UTC
(In reply to comment #8)
> The testcase from comment #3 still crashes on the 3.4 branch:

Please open a new bug.
Comment 11 Volker Reichelt 2005-07-11 16:05:05 UTC
The new PR for the problem in comment #3 is PR 22409.