This is the mail archive of the gcc-bugs@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]

Inline Assembly Register Allocation Bug? (Was: Possible bug with gcc 2.95.2 on Hitachi h8)


Hi,

I reduced the bug mentioned in:

http://gcc.gnu.org/ml/gcc-bugs/2000-07/msg00404.html

to the following level. If I am not mistaken on usage of the inline
assembly, the problem is that the same register gets assigned to two
pseudo-registers: %0 and %1. It occurs on both i386 and h8 latest gcc
from CVS, but not on on i386 egcs 1.1.2 included in RedHat Linux
6.2. I am afraid I am missing something very simple.

All I am trying to do in the function is to return an integer value
pointed to by the argument p. Just to show the possible bug, I am
copying the value twice.

/* h8300-hms-gcc -mh     -Wall -O2 -fomit-frame-pointer */
/* i386-redhat-linux-gcc -Wall -O2 -fomit-frame-pointer */
int
test (p)
     const int *p;
{
#if 1
  int temp;

#if defined (__i386__)
  asm volatile ("movl\t(%1),%0\n\t"
		"movl\t(%1),%0"
		: "=r" (temp) : "r" (p));
#else
  asm volatile ("mov.w\t@%1,%0\n\t"
		"mov.w\t@%1,%0"
		: "=r" (temp) : "r" (p));
#endif

  return temp;
#else
  /* Equivalent in C.  */
  return *p;
#endif
}

On i386 (thanks to CodeSoucery):

.globl test
        .type    test,@function
test:
        movl    4(%esp), %eax
#APP
        movl    (%eax),%eax <- the same registers on both sides!
        movl    (%eax),%eax <- this is bad!
#NO_APP
        ret

On H8/300H (or H8/S):

_main:
; #APP
	mov.w	@er0,r0 <- again, the same thing
	mov.w	@er0,r0
; #NO_APP
	rts

Thanks,

Kazu Hirata


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