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]

gcc 2.95.3 for ppc uses GPR 0 in addi


The following C code with user-provided asm code
causes gcc to produce incorrect assembler output:

[kcooper@graylock adderror]$ /usr/bin/gcc-2.95.3 -v --save-temps -c
waitfor.c
Reading specs from /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/specs
gcc version 2.95.3 19991030 (prerelease)
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/cpp -lang-c -v -D__GNUC__=2
-D__GNUC_MINOR__=95 -DPPC -D__ELF__ -Dpowerpc -D__PPC__ -D__ELF__
-D__powerpc__ -D__PPC -D__powerpc -Acpu(powerpc) -Amachine(powerpc)
-D__CHAR_UNSIGNED__ -D_CALL_SYSV -D_BIG_ENDIAN -D__BIG_ENDIAN__
-Amachine(bigendian) -D_ARCH_PPC -D__unix__ -D__linux__ -Dunix -Dlinux
-Asystem(unix) -Asystem(posix) waitfor.c waitfor.i
GNU CPP version 2.95.3 19991030 (prerelease) (PowerPC GNU/Linux)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 
/usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/../../../../ppc-redhat-linux/includ
e
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/../../../../include/g++-3
End of omitted list.
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/cc1 waitfor.i -quiet -dumpbase
waitfor.c -version -o waitfor.s
GNU C version 2.95.3 19991030 (prerelease) (ppc-redhat-linux) compiled by
GNU C
version 2.95.3 19991030 (prerelease).
 as -mppc -V -Qy -o waitfor.o waitfor.s
GNU assembler version 990418 (ppc-redhat-linux) using BFD version 990418

The preprocessed source is:

[kcooper@graylock adderror]$ cat waitfor.i
# 1 "waitfor.c"

void waitfor (int delta)
{
  asm
  (
    "addi    %%r4,%0,1\n\t"
    "mftb    %%r6\n\t"
    "add     %%r4,%%r4,%%r6\n\t"
    "1: mftb %%r5\n\t"
    "cmpl    0,%%r4,%%r5\n\t"
    "bgt     1b\n\t"
    :
    : "r" (delta)
    : "r4", "r5", "r6"
  );
}


The resulting .s file chooses r0 to load the input parameter,
resulting in an addi  r4,r0,1 instruction which effectively
zeroes the input parameter.

Perhaps the powerpc configuration file should forbid the use
of r0 when it will be the source register in an addi or subi
instruction.

Karl Cooper
Senior Software Engineer
Transcept, Inc.

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