Bug 14801 - wrong-code, gcc -O2 mixed FPU and MMX instructions
Summary: wrong-code, gcc -O2 mixed FPU and MMX instructions
Status: RESOLVED DUPLICATE of bug 19161
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.3.4
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
: 16872 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-03-31 19:33 UTC by Serge Belyshev
Modified: 2004-12-27 00:24 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 3.3.4 3.4.0 4.0.0 tree-ssa
Last reconfirmed: 2004-03-31 20:05:03


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Serge Belyshev 2004-03-31 19:33:12 UTC
---------------------------------
cat >bug.c<<EOF
#include <stdlib.h>

typedef int di __attribute__ ((mode(DI)));

double x;
di mm;

double f ()
{
	return 1.0;
}

void f2 ()
{
	x = f ();
	mm = __builtin_ia32_pxor (mm, mm);
	
	/* clear MMX state after using MMX unit */
	__builtin_ia32_emms ();
}

int main ()
{
	f2 ();
	if (x != 1.0)
		abort ();
	return 0;
}
EOF
gcc -O2 -mmmx bug.c -o bug
./bug
---------------------------------

I get 'Aborted' with 3.3.4, 3.4.0, 3.5.0, and do not get it if I compile this
with -O1.

Below is an assembly code for f2 (), compiled with today's 3.4.0:
f2:
	pushl	%ebp	#
	movl	%esp, %ebp	#,
	call	f	#
	movq	mm, %mm0	# mm, mm
	fstpl	x	# x
	pxor	%mm0, %mm0	#, mm
	movq	%mm0, mm	# mm, mm
	emms
	leave
	ret

FPU insns should not be mixed with MMX ones, or they will fail.
Comment 1 Andrew Pinski 2004-03-31 20:05:02 UTC
Confirmed, the problem is with the schedular, using -fno-schedule-insns2 "fixes" the problem.
Comment 2 Andrew Pinski 2004-07-01 04:17:23 UTC
This is better bug still a problem, right? 

       pushl   %ebp
        movl    %esp, %ebp
        call    f
        pxor    %mm0, %mm0
        movq    %mm0, mm
        fstpl   x
        emms
        popl    %ebp
        ret

Comment 3 Andrew Pinski 2004-08-04 15:56:51 UTC
*** Bug 16872 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2004-08-05 15:46:06 UTC
*** Bug 16872 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Pinski 2004-12-27 00:24:00 UTC

*** This bug has been marked as a duplicate of 19161 ***