Bug 17853

Summary: [3.4 Regression] -O2 ICE for MMX testcase
Product: gcc Reporter: Stuart Hastings <stuart>
Component: rtl-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, hubicka
Priority: P2 Keywords: ice-on-valid-code, patch
Version: 4.0.0   
Target Milestone: 3.4.3   
Host: i686-linux-gnu Target: i686-linux-gnu
Build: i686-linux-gnu Known to work: 3.3.3 4.0.0
Known to fail: 3.4.3 Last reconfirmed: 2004-10-05 22:21:37
Attachments: rejected patch

Description Stuart Hastings 2004-10-05 21:41:48 UTC
gcc -O2 -mmmx i386-mmx-5.c
GCC fails thus:
---------------------------------------------
i386-mmx-5.c: In function 'main':
i386-mmx-5.c:15: internal compiler error: in simplify_binary_operation, at simplify-rtx.c:2151
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
---------------------------------------------
/* { dg-do run { target i?86-*-* x86_64-*-* } } */
/* { dg-options "-O2 -mmmx" } */
#include <mmintrin.h>
#include <stdlib.h>

__m64 global_mask;

main()
{
    __m64 zero = _mm_setzero_si64();
    __m64 mask = _mm_cmpeq_pi8( zero, zero );
    mask = _mm_unpacklo_pi8( mask, zero );
    global_mask = mask;
    exit(0);
}
-----------------------------------------------------
Comment 1 Andrew Pinski 2004-10-05 22:21:37 UTC
Confirmed, the problem comes down to:
(insn 29 28 31 0 (set (reg:V8QI 59 [ D.2054 ])
        (eq:V8QI (reg:V8QI 60 [ D.2051 ])
            (reg:V8QI 60 [ D.2051 ]))) 627 {eqv8qi3} (insn_list 28 (nil))
    (expr_list:REG_EQUAL (const_int 1 [0x1])
        (nil)))

Looks like CSE is adding the REG_EQUAL for no reason.
Comment 2 Andrew Pinski 2004-10-05 22:22:28 UTC
Really the const_int should be instead a const_vect.
Comment 3 Andrew Pinski 2004-10-05 22:32:23 UTC
: Search converges between 2003-02-08-trunk (#179) and 2003-02-10-trunk (#180).
I almost this it was caused by:

2003-02-09  Jan Hubicka  <jh@suse.cz>

        * i386.md (ahi?v*3): Set third operand type to TImode.
        * i386.c (ix86_expand_binop_builtin): Extend operand when needed.

        * simplify-rtx.c (simplify_subreg): Fix conversion from vector into
        integer mode.

        * rtl.def (VEC_MERGE, VEC_SELECT, VEC_CONCAT, VEC_DUPLICATE):
        Change code so they are arithmetic expressions now.
        * simplify-rtx.c (simplify_unary_operation, simplify_binary_operation,
        simplify_ternary_operation): Deal with VEC_* expressions.

        * i386.md (vmaskcmp, pinsrw, movd patterns):  Fix RTL representation.
Comment 4 Stuart Hastings 2004-10-07 23:25:19 UTC
Created attachment 7306 [details]
rejected patch

Attached is the patch I offered; it was rejected.  Here is the mailing list
thread:

http://gcc.gnu.org/ml/gcc-patches/2004-10/threads.html#00317
Comment 5 GCC Commits 2004-10-09 19:28:00 UTC
Subject: Bug 17853

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	sayle@gcc.gnu.org	2004-10-09 19:27:55

Modified files:
	gcc            : ChangeLog simplify-rtx.c 
	gcc/doc        : rtl.texi tm.texi 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: i386-mmx-5.c 

Log message:
	2004-10-09  Roger Sayle  <roger@eyesopen.com>
	
	PR rtl-optimization/17853
	* simplify-rtx.c (simplify_relational_operation): Correct comment.
	Reorganize handling of comparison operations with floating point
	results (always return 0.0 even without FLOAT_STORE_FLAG_VALUE).
	Likewise, introduce support for comparison operations with vector
	result types, introducing a new VECTOR_STORE_FLAG_VALUE target macro.
	
	* doc/rtl.texi: Document new VECTOR_STORE_FLAG_VALUE target macro.
	* doc/tm.texi: Likewise.
	
	2004-10-09  Stuart Hastings  <stuart@apple.com>
	Roger Sayle  <roger@eyesopen.com>
	
	PR rtl-optimization/17853
	* gcc.dg/i386-mmx-5.c: New testcase.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.5821&r2=2.5822
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/simplify-rtx.c.diff?cvsroot=gcc&r1=1.204&r2=1.205
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/doc/rtl.texi.diff?cvsroot=gcc&r1=1.72&r2=1.73
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/doc/tm.texi.diff?cvsroot=gcc&r1=1.378&r2=1.379
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4421&r2=1.4422
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/i386-mmx-5.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 Andrew Pinski 2004-10-09 20:10:41 UTC
Fixed on the mainline.
Comment 7 Andrew Pinski 2004-10-10 17:52:54 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-10/msg00859.html>.
Comment 8 GCC Commits 2004-10-10 21:53:41 UTC
Subject: Bug 17853

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	sayle@gcc.gnu.org	2004-10-10 21:53:39

Modified files:
	gcc            : ChangeLog combine.c cse.c simplify-rtx.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: i386-mmx-5.c 

Log message:
	2004-10-10  Roger Sayle  <roger@eyesopen.com>
	
	PR rtl-optimization/17853
	* combine.c (combine_simplify_rtx): Don't attempt any simplifications
	of vector mode comparison operators.
	* cse.c (fold_rtx): Likewise.
	* simplify-rtx.c (simplify_gen_relational):  Avoid calling
	simplify_relational_operation with vector mode comparison operators.
	(simplify_rtx): Likewise.
	
	2004-10-10  Stuart Hastings  <stuart@apple.com>
	Roger Sayle  <roger@eyesopen.com>
	
	PR rtl-optimization/17853
	* gcc.dg/i386-mmx-5.c: New testcase.

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.652&r2=2.2326.2.653
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/combine.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.400.4.9&r2=1.400.4.10
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cse.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.278.4.6&r2=1.278.4.7
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.2&r2=1.172.4.3
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.282&r2=1.3389.2.283
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/i386-mmx-5.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.4.1

Comment 9 Andrew Pinski 2004-10-10 21:56:12 UTC
Fixed.