Skip to content

Input constraints for inline assembler are not used for CSE #9889

@jsonn

Description

@jsonn
Bugzilla Link 9517
Version trunk
OS Linux
CC @echristo,@efriedma-quic

Extended Description

Consider the following program:

static inline void
outb(unsigned short port, unsigned char data)
{
__asm volatile("outb %%al,%w1" : : "a" (data), "d" (port));
}

extern unsigned short base;

void test(void)
{
outb(base + 16, 0x0);
outb(base + 16, 0x1);
outb(base + 16, 0x2);
outb(base + 16, 0x3);
outb(base + 16, 0x4);
outb(base + 16, 0x5);
outb(base + 16, 0x6);
outb(base + 16, 0x7);
outb(base + 16, 0x8);
}

This should be compiled into something like:

movzwl base, %edx
add 0x10, %edx
xorl %eax, %eax
outb %al,%dx
movb $1, %al
outb %al,%dx
movb $2, %al
outb %al,%dx
...

or even better in terms of code size:

movzwl base, %edx
add 0x10, %edx
xorl %eax, %eax
outb %al,%dx
incl %eax
outb %al,%dx
incl %eax
outb %al,%dx
...

But currently it gets compiled to:

movzwl base, %edx
add 0x10, %edx
xorl %eax, %eax
outb %al,%dx
movzwl base, %edx
add 0x10, %edx
movb $1, %al
outb %al,%dx
movzwl base, %edx
add 0x10, %edx
movb $2, %al
outb %al,%dx
...

Input constraints are not clobbered and therefore, they don't have to be reloaded. The reload overhead in this case is significant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzilla

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions