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]

Incorrect code produced with inline functions & assembler


When compiled with -O2 -finline-functions the following code incorrectly
removes the or-with-constant code.  Removing -O2 or -finline-functions
produces code (but does not inline functions).

Compiler: egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
CPU: Celeron-400 x86 single CPU
OS: Linux 2.2.14-5.0 (Redhat 6.2 unpatched)

Further comentary:

The relevent parts of the assembler are:

/* Optimized and WRONG */
#APP
        inl %dx, %eax
        outl %eax, %dx
#NO_APP

Notice the lack of any "or".

/* Unoptimized and RIGHT */
        pushl $993
        pushl $993
        call inportl
        addl $4,%esp
        movl %eax,%eax
        movl %eax,%edx
        orl $305419896,%edx
        pushl %edx
        call outportl
        addl $8,%esp

Notice the orl.

I have not yet tried other versions of gcc.
static void outportl(unsigned long val, unsigned short portno) {
    __asm__ __volatile__ ("outl %0, %w1" : "=a" (val) : "Nd" (portno));
}

static unsigned long inportl(unsigned short portno) {
    unsigned long retval;
    __asm__ __volatile__ ("inl %w1, %0" : "=a" (retval) : "Nd" (portno));
    return retval;
}

void foo(void) {
    outportl((0x12345678ul | inportl(0x3E1u)), 0x3E1u);
}

Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
 /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cpp -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Di386 -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -D__linux__ -D__unix -D__i386 -D__linux -Asystem(posix) -D__OPTIMIZE__ -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_i386__ test.c test.i
GNU CPP version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/i386-redhat-linux/include
 /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cc1 test.i -quiet -dumpbase test.c -O2 -version -finline-functions -o test.s
GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386-redhat-linux) compiled by GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release).
 as -V -Qy -o test.o test.s
GNU assembler version 2.9.5 (i386-redhat-linux) using BFD version 2.9.5.0.22
# 1 "test.c"
static void outportl(unsigned long val, unsigned short portno) {
    __asm__ __volatile__ ("outl %0, %w1" : "=a" (val) : "Nd" (portno));
}

static unsigned long inportl(unsigned short portno) {
    unsigned long retval;
    __asm__ __volatile__ ("inl %w1, %0" : "=a" (retval) : "Nd" (portno));
    return retval;
}

void foo(void) {
    outportl((0x12345678ul | inportl(0x3E1u)), 0x3E1u);
}

	.file	"test.c"
	.version	"01.01"
gcc2_compiled.:
.text
	.align 4
.globl foo
	.type	 foo,@function
foo:
	pushl %ebp
	movl %esp,%ebp
	movl $993,%edx
#APP
	inl %dx, %eax
	outl %eax, %dx
#NO_APP
	leave
	ret
.Lfe1:
	.size	 foo,.Lfe1-foo
	.ident	"GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)"

binary object file produced


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