Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Inline assembler dies on WindowMaker source file (wrlib/x86_specific.c) #10173

Open Quuxplusone opened 13 years ago

Quuxplusone commented 13 years ago
Bugzilla Link PR9837
Status NEW
Importance P normal
Reported by Dimitry Andric (dimitry@andric.com)
Reported on 2011-05-04 04:14:34 -0700
Last modified on 2018-02-23 08:40:41 -0800
Version trunk
Hardware PC FreeBSD
CC anton@korobeynikov.info, atrick@apple.com, echristo@gmail.com, ismail@i10z.com, llvm-bugs@lists.llvm.org, llvm-dev@ndave.org, llvm@sunfishcode.online, nlewycky@google.com, stoklund@2pi.dk
Fixed by commit(s)
Attachments wmasm.c (7099 bytes, text/plain)
Blocks
Blocked by
See also
Created attachment 6526
Problematic inline assembly from WindowMaker

Clang's inline assembler, as of r130836, dies on this file, when
compiling it for i386:

http://hg.windowmaker.info/wmaker/file/7accebd7c65b/wrlib/x86_specific.c

with the following error:

==================================================
fatal error: error in backend: Ran out of registers during register allocation!
Please check your inline asm statement for invalid constraints:
INLINEASM <es:pushl %ebx
        movl  $7, %eax
        movl  $8, %ebx
        movl  $9, %ecx
        movw  %ax, $16
        movw  %bx, $17
        movw  %cx, $18
        movw  $$0,  $19
        movq  $16, %mm6
        movl $$0x00040004, $16
        movl $$0x00040004, $18
        movq $16, %mm7
        movl $$0x00070007, $16
        movl $$0x00070007, $18
        movq $16, %mm5
        movl $$0x00050005, $16
        movl $$0x00050005, $18
        movq $16, %mm4
        movl $$0x00030003, $16
        movl $$0x00030003, $18
        movq $16, %mm3
        movl $0, %esi
.LoopYa:
        movl $13, %eax
        movl %eax, $26
        movl $14, %eax
        decl %eax
        movl %eax, $14
        js .Enda
        andl $$1, %eax
        jz .LoopY_1a
.LoopY_0a:
        movl $2, %ebx
        movl %ebx, $25
        movl $3, %eax
        movl %eax, $24
        jmp .LoopXa
.LoopY_1a:
        movl $3, %ebx
        movl %ebx, $25
        movl $2, %eax
        movl %eax, $24
        .align 16
.LoopXa:
        movq (%ebx), %mm1
        punpcklbw (%esi), %mm0
        psrlw $$8, %mm0
        paddusb %mm1, %mm0
        movq %mm0, $20
        movzwl $20, %ecx
        movl $4, %edi
        leal (%edi, %ecx, 2), %eax
        movw (%eax), %dx
        movw %dx, $16
        movzwl $21, %ecx
        movl $5, %edi
        leal (%edi, %ecx, 2), %eax
        movw (%eax), %dx
        movw %dx, $17
        movzwl $22, %ecx
        movl $6, %edi
        leal (%edi, %ecx, 2), %eax
        movw (%eax), %dx
        movw %dx, $18
        movw $$0, $19
        movq $16, %mm1
        pmullw %mm6, %mm1
        psubsw %mm1, %mm0
        movl $25, %ebx
        movq %mm0, %mm1
        pmullw %mm5, %mm1
        psrlw %mm7, %mm1
        paddw 8(%ebx), %mm1
        movq %mm1, 8(%ebx)
        movl $24, %ebx
        movq %mm0, %mm1
        pmullw %mm4, %mm1
        psrlw %mm7, %mm1
        paddw -8(%ebx), %mm1
        movq %mm1, -8(%ebx)
        movq %mm0, %mm1
        pmullw %mm3, %mm1
        psrlw %mm7, %mm1
        paddw 8(%ebx), %mm1
        movq %mm1, (%ebx)
        psrlw %mm7, %mm0
        movq %mm0, 8(%ebx)
        movl $10, %ecx
        movw $16, %ax
        shlw %cl, %ax
        movl $11, %ecx
        movw $17, %bx
        shlw %cl, %bx
        orw %bx, %ax
        movl $12, %ecx
        movw $18, %bx
        shlw %cl, %bx
        orw %bx, %ax
        movl $1, %edx
        movw %ax, (%edx)
        addl $$2, %edx
        movl %edx, $1
        addl $$8, $24
        movl $25, %ebx
        addl $$8, %ebx
        movl %ebx, $25
        addl $$4, %esi
        decl $26
        jnz .LoopXa
        addl $15, %edx
        movl %edx, $1
        jmp .LoopYa
.Enda:
        emms
        popl %ebx
        > [sideeffect], 44, <fi#0>, 1, %noreg, 0, %noreg, 44, <fi#1>, 1, %noreg, 0, %noreg, 44, <fi#2>, 1, %noreg, 0, %noreg, 44, <fi#3>, 1, %noreg, 0, %noreg, 44, <fi#4>, 1, %noreg, 0, %noreg, 44, <fi#5>, 1, %noreg, 0, %noreg, 44, <fi#6>, 1, %noreg, 0, %noreg, 44, <fi#7>, 1, %noreg, 0, %noreg, 44, <fi#8>, 1, %noreg, 0, %noreg, 44, <fi#9>, 1, %noreg, 0, %noreg, 44, <fi#10>, 1, %noreg, 0, %noreg, 44, <fi#11>, 1, %noreg, 0, %noreg, 44, <fi#12>, 1, %noreg, 0, %noreg, 44, <fi#13>, 1, %noreg, 0, %noreg, 44, <fi#14>, 1, %noreg, 0, %noreg, 44, <fi#15>, 1, %noreg, 0, %noreg, 44, %EBX, 1, %noreg, 0, %noreg, 44, %EBP, 1, %noreg, 0, %noreg, 44, %vreg40, 1, %noreg, 0, %noreg, 44, %vreg36, 1, %noreg, 0, %noreg, 44, %vreg34, 1, %noreg, 0, %noreg, 44, %vreg32, 1, %noreg, 0, %noreg, 44, %vreg29, 1, %noreg, 0, %noreg, 44, %vreg25, 1, %noreg, 0, %noreg, 44, <fi#18>, 1, %noreg, 0, %noreg, 44, <fi#19>, 1, %noreg, 0, %noreg, 44, <fi#20>, 1, %noreg, 0, %noreg, 14, %AX<earlyclobber,imp-def>, 14, %CX<earlyclobber,imp-def>, 14, %DX<earlyclobber,imp-def>, 14, %SI<earlyclobber,imp-def>, 14, %DI<earlyclobber,imp-def>, 14, %EFLAGS<earlyclobber,imp-def>, <<badref>>; GR32:%vreg40,%vreg36,%vreg34,%vreg32,%vreg29,%vreg25
==================================================

The problematic function is x86_mmx_TrueColor_32_to_16(), which I will
add as a testcase (wmasm.c).
Quuxplusone commented 13 years ago

Attached wmasm.c (7099 bytes, text/plain): Problematic inline assembly from WindowMaker

Quuxplusone commented 13 years ago

The inlineasm instruction is using 5 virtual registers on top of the 5 clobbered registers. There is nothing the register allocator can do about that, x86 only has 6 available registers.

Those virtual registers are GEPs of stack objects. They should have been folded into the inlineasm addressing mode by isel.

BTW, the asm is modifying the stack pointer before using the "m" constraints. What could possibly go wrong!

Quuxplusone commented 13 years ago

The problem is that they're all memory constraints. Theoretically it should work since they'll just be memory operands. There are other, similar, bugs to this.

Quuxplusone commented 12 years ago

Still reproducable on trunk.

Quuxplusone commented 12 years ago

FWIW if they rewrote the code to be multiple inline asms instead of a single large one it would probably work.

Quuxplusone commented 9 years ago
Still fails on trunk:

[~]> clang -c -m32 wmasm.c
wmasm.c:35:10: error: inline assembly requires more registers than available
         "pushl %%ebx                        \n\t"
         ^
wmasm.c:35:10: error: inline assembly requires more registers than available
wmasm.c:35:10: error: inline assembly requires more registers than available
wmasm.c:35:10: error: inline assembly requires more registers than available
wmasm.c:35:10: error: inline assembly requires more registers than available
wmasm.c:35:10: error: inline assembly requires more registers than available
wmasm.c:35:10: error: inline assembly requires more registers than available
7 errors generated.