Optimizer is putting result of a log into the wrong reg

Bernd Schmidt bernds@cygnus.co.uk
Thu Sep 23 07:59:00 GMT 1999


> Oops, sorry about that. I am now passing doubles where doubles are expected
> (I also simplified it a bit). But it *still* puts a NaN into the variable
> DiscRate whereas it clearly should be 0.

Looking at the assembler output, it seems clear what's going wrong:

FuncB:
        pushl %ebp
	movl %esp,%ebp
	subl $24,%esp
	pushl %edi
	pushl %esi
	pushl %ebx
	fldl 24(%ebp)
	fldl 40(%ebp)
	fldl 56(%ebp)
	fldl 72(%ebp)
	fldl 80(%ebp)
	fldl 96(%ebp)
	fldl 104(%ebp)
	movl 124(%ebp),%edi
	movl 128(%ebp),%esi
	movl 132(%ebp),%ebx
	movl 136(%ebp),%edx
	movl 140(%ebp),%ecx
	fldl 112(%ebp)
#APP
	fldln2; fxch; fyl2x
#NO_APP

This piece of code loads nine values on the floating point stack, which has
only eight entries.
This appears to be a bug in glibc-2.1.  Here's the log function (after the
preprocessor is done with it):

extern __inline double 
log (double __x)
{
  register double __result;
  __asm __volatile__ ("fldln2; fxch; fyl2x":"=t" (__result):"0" (__x));
  return __result;
}

The asm statement is wrong, it doesn't tell the compiler that one extra
stack reg is needed.

Bernd



More information about the Gcc-bugs mailing list