"error: ran out of registers during register allocation" Have you ever seen this message?

I encountered the following error message in the x86 (32-bit) Linux environment of GitHub Actions.
error: ran out of registers during register allocation
cf. Version 0.2.3 (#35) · kimikage/ColorBlendModes.jl@3529b12 · GitHub

The message seems to be issued by LLVM, but I’m not sure. Now I don’t have enough time to analyze this problem, as the error is not reproduced on my local WOW64 or 32-bit ARM machines.

Does anyone know anything about the error? Also, is this an issue should be filed?

I thought this was an unusual case so I shared the info. I am not going to try to solve this problem right now.

I have added a workaround for this error in ColorBlendModes v0.2.4, so if you are interested in this issue, please use v0.2.3.

You can probably reproduce the error by running the following code in GItHub Actions.

using ColorBlendModes # v0.2.3
using ColorTypes
rgb = RGB(0, 0, 0)
rgbas = (RGBA(1, 0, 0), RGBA(0, 1, 0), RGBA(0, 0, 1))
BlendLighten.(rgb, rgbas)

cf. log of GitHub Actions (No error with @code_llvm, error with @code_native.)

Here are a few things I’ve learned.

  • This happens with broadcast.
  • This happens when using FixedPoint. However, FixedPoints are integer types at the LLVM IR level, so I don’t think it’s a problem with FixedPoint itself.
  • This may be related to inlining; I tried to make an MWE, but simple or overly complex operations do not raise the error.

I can’t reproduce this problem, but can you try to outline the _w function in ColorBlendModes (by @noinline). It seems that this function doesn’t gets inlined in my Julia (1.6.1 and 1.5.2) but it gets inlined in your test and generates a lots of LLVM IR.

The _w does not appear to be inlined. Am I misunderstanding something?

This is definitely an issue that should be filed if it’s still occurring.

1 Like

But log of Github action shows different output of LLVM IR, and _w is disappear. The codegen is different, so I can’t reproduce the error on my computer.

The mapc() (i.e. mapch()) is a backedge of the _w.

              %87 = call [3 x [1 x i8]] @j__mapc_459({}* readonly inttoptr (i32 -379120728 to {}*), [1 x [1 x i8]]* nocapture readonly %4, [3 x [1 x i8]]* nocapture readonly %3, [3 x [1 x i8]]* nocapture readonly %5)

I have confirmed that this mapc() by itself does not cause the problem.

I notice that there are a lots of lcnt there which is not showed in my case (after I inline w and some other functions manually to match the your Github action output), it seems that this is used for code coverage (need confirm here), and you have a lots of small nested function call which leads to hundred of lcnt instructions (and maybe that cause LLVM allocates a lot of register). Is this the real cause?

Edit: I turn on code-coverage on my computer, but it still doesn’t throw any error, even if it has hundreds of lcnt. Maybe not the cause but worth noting here.

1 Like

Good catch! By disabling the coverage, the error no longer occurs.

However, if the code for coverage is the direct cause, the error should occur in more situations. :thinking:

Anyway, now that I can reproduce this error on my local machine (WOW64), I’ll look into it some more.

Yeah, it’s super strange, since inserting these short-living operations shouldn’t break register allocation.

Maybe you should file an issue and move the discussion there. And if you can reproduce this problem, can you following this page Improving LLVM optimizations for Julia and dump all the pass information? So it’s easy to locate the problematic pass.

1 Like

xref: LLVM error "ran out of registers during register allocation" on 32-bit x86 with code-coverage · Issue #42200 · JuliaLang/julia · GitHub

1 Like