Bug 18614 - [3.4 Regression] ICE in simplify_binary_operation
Summary: [3.4 Regression] ICE in simplify_binary_operation
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: 3.4.4
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2004-11-22 22:26 UTC by Steffen Boerm
Modified: 2004-11-24 14:22 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 4.0.0
Known to fail: 3.4.3
Last reconfirmed: 2004-11-22 22:45:28


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steffen Boerm 2004-11-22 22:26:24 UTC
When I feed the following program "ice.c"

typedef double v2df __attribute__ ((mode(V2DF)));
int main()
{
  volatile v2df xd;
  v2df yd = { 1.0, 4.0 };
  xd = __builtin_ia32_cvtps2pd(__builtin_ia32_rsqrtps(__builtin_ia32_cvtpd2ps(yd)));
  return 0;
}

to GCC 3.4.3 with

gcc -march=pentium4 -mcpu=pentium4 -msse2 -funroll-loops ice.c -o ice

I get the following:

ice.c: In function `main':
ice.c:11: internal compiler error: in simplify_binary_operation, at
simplify-rtx.c:1202

If I omit "-funroll-loops", everything seems to work.

Best regards,
Steffen 8-)
Comment 1 Andrew Pinski 2004-11-22 22:45:28 UTC
Confirmed
: Search converges between 2003-03-31-trunk (#217) and 2003-04-01-trunk (#218).
Comment 2 uros 2004-11-23 13:26:40 UTC
Works OK with gcc version 4.0.0 20041123 (experimental). Following ASM is
produced with 'gcc -march=pentium4 -mcpu=pentium4 -msse2 -funroll-loops':

.LC0:
        .long  0
        .long  1072693248
        .long  0
        .long  1074790400
        .text
.globl main
        .type  main, @function
main:
        pushl  %ebp
        movl   %esp, %ebp
        subl   $40, %esp
        andl   $-16, %esp
        movl   $0, %eax       |
        addl   $15, %eax      |
        addl   $15, %eax      |
        shrl   $4, %eax       |<--- WHY?
        sall   $4, %eax       |
        subl   %eax, %esp
        movapd .LC0, %xmm0
        movapd %xmm0, -24(%ebp)
        cvtpd2ps        -24(%ebp), %xmm0
        rsqrtps %xmm0, %xmm0
        cvtps2pd        %xmm0, %xmm0
        movapd %xmm0, -40(%ebp)
        movl   $0, %eax
        leave
        ret

I don't know what is the purpouse of marked operations on %eax...
Comment 3 uros 2004-11-23 13:35:05 UTC
Oops... gcc 4.0 crashes with "-msse2 -O2", with or without -funroll-loops:

pr18614.c: In function âmainâ:
pr18614.c:12: internal compiler error: in simplify_binary_operation, at
simplify-rtx.c:1202
Comment 4 uros 2004-11-23 14:04:24 UTC
Gcc crashes with this insn:

(insn 25 24 26 0 (set (reg:V4SF 60 [ D.1457 ])
        (subreg:V4SF (vec_concat:V4SI (subreg:V2SI (float_truncate:V2SF
(reg:V2DF 73)) 0)
                (const_vector:V2SI [
                        (const_int 0 [0x0])
                        (const_int 0 [0x0])
                    ])) 0)) -1 (nil)
    (nil))

n_elts is calculated as 4, but op0_n_elts and op1_n_elts are 2 (which is kind of
obvious for vec_concat). Because a constant is loaded to (reg 73), the whole
insn simplifies to vec_concat of two constant 2-element vectors.

This triggers the asserts:
      gcc_assert (op0_n_elts == n_elts);
      gcc_assert (op1_n_elts == n_elts);

The fix would be to prevent an entry of vec_concat into simplify_binary_operation().
Comment 5 uros 2004-11-23 14:43:34 UTC
Patch here: http://gcc.gnu.org/ml/gcc-patches/2004-11/msg01867.html

Resulting ASM with '-O2 -msse2' is much better. Optimization did its job quite
well :)

.LC1:
        .long  1065353216
        .long  1082130432
        .long  0
        .long  0
        .text
        .p2align 4,,15
.globl main
        .type  main, @function
main:
        pushl  %ebp
        xorl   %eax, %eax
        movl   %esp, %ebp
        subl   $24, %esp
        rsqrtps .LC1, %xmm0
        andl   $-16, %esp
        subl   $16, %esp
        cvtps2pd        %xmm0, %xmm0
        movapd %xmm0, -24(%ebp)
        leave
        ret
Comment 6 uros 2004-11-23 16:30:27 UTC
Fixed on mainline:

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	uros@gcc.gnu.org	2004-11-23 16:20:51

Modified files:
	gcc            : ChangeLog simplify-rtx.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: pr18614-1.c 

Log message:
	rtl-optimization/18614
	* simplify-rtx.c (simplify_binary_operation): Do not
	simplify inner elements of constant arguments of
	VEC_CONCAT insn.
	
	testsuite:
	
	* gcc.dg/pr18614-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6487&r2=2.6488
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/simplify-rtx.c.diff?cvsroot=gcc&r1=1.208&r2=1.209
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4632&r2=1.4633
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr18614-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Could someone please commit this one-liner to 3.4 branch?
Comment 7 Giovanni Bajo 2004-11-23 17:07:45 UTC
Did you do a bootstrap & test cycle on 3.4 as well?
Comment 8 uros 2004-11-24 07:31:03 UTC
(In reply to comment #7)
> Did you do a bootstrap & test cycle on 3.4 as well?

Yes. But I need some kind of permission to install this patch & testcase on 3.4
branch.
Comment 9 GCC Commits 2004-11-24 14:21:46 UTC
Subject: Bug 18614

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	uros@gcc.gnu.org	2004-11-24 14:20:57

Modified files:
	gcc            : ChangeLog simplify-rtx.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: pr18614-1.c 

Log message:
	PR rtl-optimization/18614
	* simplify-rtx.c (simplify_binary_operation): Do not
	simplify inner elements of constant arguments of
	VEC_CONCAT insn.
	
	testsuite:
	
	* gcc.dg/pr18614-1.c: New test.

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.701&r2=2.2326.2.702
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/simplify-rtx.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.172.4.3&r2=1.172.4.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.311&r2=1.3389.2.312
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr18614-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 10 uros 2004-11-24 14:22:56 UTC
Fixed on 3.4 branch.