[LLVMbugs] [Bug 16327] New: Poor register allocation compiling GCC inline assembly (x86)
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Jun 13 17:56:30 PDT 2013
http://llvm.org/bugs/show_bug.cgi?id=16327
Bug ID: 16327
Summary: Poor register allocation compiling GCC inline assembly
(x86)
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Backend: X86
Assignee: unassignedbugs at nondot.org
Reporter: lennox at cs.columbia.edu
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Created attachment 10679
--> http://llvm.org/bugs/attachment.cgi?id=10679&action=edit
File using GCC inline assembly with lots of inputs
(Note: this is similar to bug 16326, but for the x86 backend.)
The register allocation to constraints to GCC inline assembly is very poor,
leading to very inefficient code, shuffling values on and off the stack
entirely redundantly, or between the stack and variables.
Consider reg-overload-i386.c (attached).
For 32-bit mode, LLVM generates the following code. Notice the shuffling of
values off the stack and then back onto it, prior to InlineAsm Start.
_foo: ## @foo
## BB#0: ## %entry
pushl %ebp
movl %esp, %ebp
pushl %edi
pushl %esi
subl $32, %esp
movl 8(%ebp), %eax
movl %eax, -12(%ebp)
movl 12(%ebp), %eax
movl %eax, -16(%ebp)
movl 16(%ebp), %eax
movl %eax, -20(%ebp)
movl 20(%ebp), %eax
movl %eax, -24(%ebp)
movl 24(%ebp), %eax
movl %eax, -28(%ebp)
movl 28(%ebp), %eax
movl %eax, -32(%ebp)
movl 32(%ebp), %eax
movl %eax, -36(%ebp)
movl 36(%ebp), %eax
movl %eax, -40(%ebp)
## InlineAsm Start
mov -12(%ebp), %eax
mov (%eax), %ecx
mov -16(%ebp), %edx
mov -20(%ebp), %edi
mov -24(%ebp), %esi
add %edx, %ecx
add %edi, %ecx
add %esi, %ecx
mov -28(%ebp), %edx
mov -32(%ebp), %edi
mov -36(%ebp), %esi
add %edx, %ecx
add %edi, %ecx
add %esi, %ecx
mov -40(%ebp), %edx
add %edx, %ecx
mov %ecx, (%eax)
## InlineAsm End
addl $32, %esp
popl %esi
popl %edi
popl %ebp
ret
gcc-4.2, by contrast, directly passes the function arguments to the inline
assembly:
.text
.align 4,0x90
.globl _foo
_foo:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl %esi, (%esp)
movl %edi, 4(%esp)
mov 8(%ebp), %eax
mov (%eax), %ecx
mov 12(%ebp), %edx
mov 16(%ebp), %edi
mov 20(%ebp), %esi
add %edx, %ecx
add %edi, %ecx
add %esi, %ecx
mov 24(%ebp), %edx
mov 28(%ebp), %edi
mov 32(%ebp), %esi
add %edx, %ecx
add %edi, %ecx
add %esi, %ecx
mov 36(%ebp), %edx
add %edx, %ecx
mov %ecx, (%eax)
movl (%esp), %esi
movl 4(%esp), %edi
leave
ret
Similarly, on x86_64, clang shuffles the function arguments from registers onto
the stack:
_foo: ## @foo
.cfi_startproc
## BB#0: ## %entry
pushq %rbp
Ltmp2:
.cfi_def_cfa_offset 16
Ltmp3:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp4:
.cfi_def_cfa_register %rbp
movq %rdi, -8(%rbp)
movl %esi, -12(%rbp)
movl %edx, -16(%rbp)
movl %ecx, -20(%rbp)
movl %r8d, -24(%rbp)
movl %r9d, -28(%rbp)
movl 24(%rbp), %eax
movl 16(%rbp), %ecx
movl %ecx, -32(%rbp)
movl %eax, -36(%rbp)
## InlineAsm Start
mov -8(%rbp), %eax
mov (%eax), %ecx
mov -12(%rbp), %edx
mov -16(%rbp), %edi
mov -20(%rbp), %esi
add %edx, %ecx
add %edi, %ecx
add %esi, %ecx
mov -24(%rbp), %edx
mov -28(%rbp), %edi
mov -32(%rbp), %esi
add %edx, %ecx
add %edi, %ecx
add %esi, %ecx
mov -36(%rbp), %edx
add %edx, %ecx
mov %ecx, (%eax)
## InlineAsm End
popq %rbp
ret
.cfi_endproc
Whereas gcc directly uses the registers:
_foo:
LFB2:
pushq %rbp
LCFI0:
movq %rsp, %rbp
LCFI1:
movq %rbx, -16(%rbp)
LCFI2:
movq %r12, -8(%rbp)
LCFI3:
movq %rdi, %r12
movl %esi, %ebx
movl %edx, %r11d
movl %ecx, %r10d
mov %r12, %eax
mov (%eax), %ecx
mov %ebx, %edx
mov %r11d, %edi
mov %r10d, %esi
add %edx, %ecx
add %edi, %ecx
add %esi, %ecx
mov %r8d, %edx
mov %r9d, %edi
mov 16(%rbp), %esi
add %edx, %ecx
add %edi, %ecx
add %esi, %ecx
mov 24(%rbp), %edx
add %edx, %ecx
mov %ecx, (%eax)
movq -16(%rbp), %rbx
movq -8(%rbp), %r12
leave
ret
This is clang tip:
$ clang -v
clang version 3.4 (trunk 183951) (llvm/trunk 183950)
Target: x86_64-apple-darwin12.4.0
Thread model: posix
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130614/8e9d3838/attachment.html>
More information about the llvm-bugs
mailing list