This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH]: Fix __builtin_apply problems with MMX registers


On 7/14/05, Richard Guenther <richard.guenther@gmail.com> wrote:

> >   The proposed solution introduces two defines, that overload
> > FUNCTION_VALUE_REGNO_P and FUNCTION_ARG_REGNO_P defines in builtin_apply.c. With
> > this change __builtin_apply, __builtin_apply_args and __builtin_return don't
> > reference MMX registers anymore, while MMX registers can still be used as
> > function regparms / return registers for other functions.
> >
> >   This problem is unrelated to MMX/x87 switching patch.

> Do you have a testcase?

Another testcase that fails with -O2 -mmmx is gcc.dg/builtin-apply4.c.

Without the patch, following code is generated with current mainline:

bar:
	pushl	%ebp
	movl	%esp, %ebp
	pushl	%edi
	pushl	%esi
	pushl	%ebx
	subl	$200, %esp
	movl	%eax, -68(%ebp)
	movl	%edx, -64(%ebp)
	movl	%ecx, -60(%ebp)
	movq	%mm0, -56(%ebp)   <<< FPU switches to MMX mode here
	movq	%mm1, -48(%ebp)
	movq	%mm2, -40(%ebp)
	leal	8(%ebp), %eax
	movl	%eax, -72(%ebp)
	pushl	8(%ebp)
	call	foo
	fstp	%st(0)
	movl	-72(%ebp), %esi
	addl	$16, %esp
	movl	%esp, %ebx
	subl	$32, %esp
	cld
	movl	%esp, %edi
	movsl
	movsl
	movsl
	movsl
	movl	-68(%ebp), %eax
	movl	-64(%ebp), %edx
	movl	-60(%ebp), %ecx
	movq	-56(%ebp), %mm0
	movq	-48(%ebp), %mm1
	movq	-40(%ebp), %mm2
	call	foo
	fstp	%st(1)
	movl	%eax, -200(%ebp)
	fstpt	-196(%ebp)
	movq	%mm0, -184(%ebp)
	movl	%ebx, %esp
	movl	-200(%ebp), %eax
	fldt	-196(%ebp)
	movq	-184(%ebp), %mm0
	leal	-12(%ebp), %esp
	popl	%ebx
	popl	%esi
	popl	%edi
	leave
	ret

./a.out
Aborted

And with attached patch:

bar:
	pushl	%ebp
	movl	%esp, %ebp
	pushl	%ebx
	subl	$164, %esp
	movl	%eax, -20(%ebp)
	leal	8(%ebp), %eax
	movl	%esp, %ebx
	movl	%eax, -24(%ebp)
	movl	8(%ebp), %eax
	movl	%edx, -16(%ebp)
	movl	%ecx, -12(%ebp)
	movl	%eax, (%esp)
	call	foo
	fstp	%st(0)
	movl	-24(%ebp), %edx
	subl	$32, %esp
	movl	(%edx), %eax
	movl	%eax, (%esp)
	movl	4(%edx), %eax
	movl	%eax, 4(%esp)
	movl	8(%edx), %eax
	movl	%eax, 8(%esp)
	movl	12(%edx), %eax
	movl	%eax, 12(%esp)
	movl	-20(%ebp), %eax
	movl	-16(%ebp), %edx
	movl	-12(%ebp), %ecx
	call	foo
	fstp	%st(1)
	fstpt	-148(%ebp)
	movl	%eax, -152(%ebp)
	movl	-152(%ebp), %eax
	movl	%ebx, %esp
	movl	-4(%ebp), %ebx
	fldt	-148(%ebp)
	leave
	ret
./a.out

It works.
Also works with -O2 -msse2, so I wonder why x86_64 didn't crash on
this testcase before, as it enables MMX and SSE by default.

Uros.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]