Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

inline asm: Ran out of registers during register allocation! #5515

Open Quuxplusone opened 15 years ago

Quuxplusone commented 15 years ago
Bugzilla Link PR5010
Status NEW
Importance P normal
Reported by Bernhard Rosenkraenzer (bero@lindev.ch)
Reported on 2009-09-19 18:44:00 -0700
Last modified on 2010-03-04 16:38:13 -0800
Version trunk
Hardware Other Linux
CC anton@korobeynikov.info, castet.matthieu@free.fr, chris@growl.info, clattner@nondot.org, dalej@apple.com, efriedma@quicinc.com, hinokind@gmail.com, llvm-bugs@lists.llvm.org, regehr@cs.utah.edu
Fixed by commit(s)
Attachments mpegvideo_mmx.i (263300 bytes, application/octet-stream)
bugpoint-reduced-simplified.bc (5240 bytes, application/octet-stream)
Blocks
Blocked by
See also
llvm-gcc -DHAVE_AV_CONFIG_H -I. -I"/usr/src/ark/BUILD/ffmpeg" -D_ISOC99_SOURCE -
D_POSIX_C_SOURCE=200112 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -m32 -O2 -
march=i686 -fomit-frame-pointer -fweb -frename-registers -mmmx -g -fomit-frame-
pointer -ffast-math --std=gnu99 -O2  -std=c99 -pthread -I/usr/include/dirac -g -
Wdeclaration-after-statement -Wall -Wno-switch -Wdisabled-optimization -
Wpointer-arith -Wredundant-decls -Wno-pointer-sign -Wcast-qual -Wwrite-strings -
Wundef -O3 -fno-math-errno -fno-tree-vectorize         -MMD -MF
libavcodec/x86/dsputilenc_mmx.d -MT libavcodec/x86/dsputilenc_mmx.o -c -o
libavcodec/x86/dsputilenc_mmx.o libavcodec/x86/dsputilenc_mmx.c
cc1: error in backend: Ran out of registers during register allocation!
Please check your inline asm statement for invalid constraints:
INLINEASM <es:movd %eax, %xmm3
        pshuflw $$0, %xmm3, %xmm3
        punpcklwd %xmm3, %xmm3
        pxor %xmm7, %xmm7
        pxor %xmm4, %xmm4
        movdqa ($2), %xmm5
        pxor %xmm6, %xmm6
        psubw ($3), %xmm6
        mov $$-128, %eax
        .align 1 << 4
        1:
        movdqa ($1, %eax), %xmm0
        movdqa %xmm0, %xmm1
        pabsw  %xmm0, %xmm0
        psubusw %xmm6, %xmm0
        pmulhw %xmm5, %xmm0
        por %xmm0, %xmm4
        psignw %xmm1, %xmm0
        movdqa %xmm0, ($5, %eax)
        pcmpeqw %xmm7, %xmm0
        movdqa ($4, %eax), %xmm1
        movdqa %xmm7, ($1, %eax)
        pandn %xmm1, %xmm0
        pmaxsw %xmm0, %xmm3
        add $$16, %eax
         js 1b
        movhlps %xmm3, %xmm0
        pmaxsw %xmm0, %xmm3
        pshuflw $$0x0E, %xmm3, %xmm0
        pmaxsw %xmm0, %xmm3
        pshuflw $$0x01, %xmm3, %xmm0
        pmaxsw %xmm0, %xmm3
        movd %xmm3, %eax
        movzb %al, %eax
        >, 10, %EAX<def>, 9, %reg1348<kill>, 9, %reg1301<kill>, 9, %reg1345<kill>, 9, %reg1343<kill>, 9, %reg1346<kill>, 2147483657, %EAX, 14, %EFLAGS<earlyclobber,def,dead> [dbg: /usr/src/ark/BUILD/ffmpeg/libavcodec/x86/mpegvideo_mmx_template.c,152,0]

gcc 4.4.x compiles the code without problems.
Quuxplusone commented 15 years ago

Attached mpegvideo_mmx.i (263300 bytes, application/octet-stream): Preprocessed source showing the problem

Quuxplusone commented 15 years ago
Problem occurs only with a combination of -O and -fomit-frame-pointer.
Easiest way to reproduce:

llvm-gcc -O -fomit-frame-pointer -c mpegvideo_mmx.i
Quuxplusone commented 15 years ago

I believe that this works on mainline, the fix didn't make it into 2.6.

Quuxplusone commented 15 years ago
(In reply to comment #3)
> I believe that this works on mainline, the fix didn't make it into 2.6.
No, fails for me on tot. Reducing.
Quuxplusone commented 15 years ago

Attached bugpoint-reduced-simplified.bc (5240 bytes, application/octet-stream): Bugpoint reduction

Quuxplusone commented 15 years ago

EDX is live across the big asm, so the only way to get enough registers is spill EDX. Apparently it doesn't know how to do that. The def and use of EDX are made into a "fixed interval" which, I think, isn't considered for spilling. Maybe we shouldn't do that when there's an asm in the range?

Compiles with the simple RA but the code isn't right, EAX tries to hold multiple values in a couple of places. Appears to produce correct code with local RA.

Quuxplusone commented 15 years ago

I haven't looked carefully, but I think this is a dup of bug 4668.

Quuxplusone commented 15 years ago
Here's another testcase if anyone is interested...

regehr@john-home:~/volatile/tmp216$ clang -v
clang version 1.1 (trunk 85644)
Target: i386-pc-linux-gnu
Thread model: posix

regehr@john-home:~/volatile/tmp216$ clang -c -w -Os small.c

fatal error: error in backend: Ran out of registers during register allocation!

regehr@john-home:~/volatile/tmp216$ cat small.c

static unsigned char
foo (char _left, unsigned int _right)
{
  return _left || _right >= 1 * 8 ? _left : _left >> _right;
}

static unsigned short
bar (unsigned short _ui1, unsigned char _ui2)
{
  return 0 ? : (_ui1 % _ui2);
}

unsigned char g_147;
uint648 (short p_9, int int32p11, unsigned char p_12, int uint32p_13)
{
  unsigned char l_131;
  unsigned char *l = &l_131;
  for (l;; 1)
    {
      unsigned char l_153;
      if (func_46 (0) |
      bar (foo
           (g_147,
        +p_12) ^
           foo (func_39
            (0),
            p_9 != 0) >
           (safe (0), 0), ~l_153))
    assert (&l_131);
    }
}
Quuxplusone commented 14 years ago

_Bug 5362 has been marked as a duplicate of this bug._

Quuxplusone commented 14 years ago
Another one I got by building ffmpeg as llvm bytecode (-O4) and then building
native code from the bytecode [1]

Note that building native code with clang (-O3) doesn't produce any error for
me (svn version of yesterday).

[1]
Generating Bitcode To ffmpeg_g.bc
Generating Assembly With:
'/data/build/userspace/llvm/llvm/Release/bin/llc' '-x86-asm-syntax=att' '-f' '-
o' 'ffmpeg_g.s' 'ffmpeg_g.bc'
LLVM ERROR: Ran out of registers during register allocation!
Please check your inline asm statement for invalid constraints:
INLINEASM <es:movd %eax, %mm3
        pshufw $$0, %mm3, %mm3
        pxor %mm7, %mm7
        pxor %mm4, %mm4
        movq ($2), %mm5
        pxor %mm6, %mm6
        psubw ($3), %mm6
        mov $$-128, %eax
        .align 1 << 4
        1:
        movq ($1, %eax), %mm0
        pxor %mm1, %mm1
        pcmpgtw %mm0, %mm1
        pxor %mm1, %mm0
        psubw %mm1, %mm0
        psubusw %mm6, %mm0
        pmulhw %mm5, %mm0
        por %mm0, %mm4
        pxor %mm1, %mm0
        psubw %mm1, %mm0
        movq %mm0, ($5, %eax)
        pcmpeqw %mm7, %mm0
        movq ($4, %eax), %mm1
        movq %mm7, ($1, %eax)
        pandn %mm1, %mm0
        pmaxsw %mm0, %mm3
        add $$8, %eax
         js 1b
        pshufw $$0x0E, %mm3, %mm0
        pmaxsw %mm0, %mm3
        pshufw $$0x01, %mm3, %mm0
        pmaxsw %mm0, %mm3
        movd %mm3, %eax
        movzb %al, %eax
        >, 10, %EAX<def>, 9, %reg1326<kill>, 9, %reg1332, 9, %reg1323<kill>, 9, %reg1320<kill>, 9, %reg1321<kill>, 2147483657, %EAX, 14, %EFLAGS<earlyclobber,def,dead>; dbg:mpegvideo_mmx_template.c:152:9