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

**URL:** <https://discourse.julialang.org/t/error-ran-out-of-registers-during-register-allocation-have-you-ever-seen-this-message/60153>\
**Category:** New to Julia\
**Tags:** llvm\
**Created:** [April 28, 2021, 9:29am UTC](https://discourse.julialang.org/t/error-ran-out-of-registers-during-register-allocation-have-you-ever-seen-this-message/60153 "2021-04-28T09:29:14Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)\
**Post date:** [April 28, 2021, 9:29am UTC](https://discourse.julialang.org/t/error-ran-out-of-registers-during-register-allocation-have-you-ever-seen-this-message/60153/1 "2021-04-28T09:29:15Z")

</div>

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. [https://github.com/kimikage/ColorBlendModes.jl/runs/2445506156#step:5:61](https://github.com/kimikage/ColorBlendModes.jl/runs/2445506156#step:5:61)

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.

---

<div class="post-metadata">

**Author:** ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)\
**Post date:** [September 9, 2021, 5:18am UTC](https://discourse.julialang.org/t/error-ran-out-of-registers-during-register-allocation-have-you-ever-seen-this-message/60153/2 "2021-09-09T05:18:43Z")

</div>

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.

```julia
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](https://github.com/kimikage/ColorBlendModes.jl/runs/3554787389#step:5:1018) (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, `FixedPoint`s 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.

---

<div class="post-metadata">

**Author:** ![anon56330260](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@anon56330260](https://discourse.julialang.org/u/anon56330260)\
**Post date:** [September 9, 2021, 1:28pm UTC](https://discourse.julialang.org/t/error-ran-out-of-registers-during-register-allocation-have-you-ever-seen-this-message/60153/3 "2021-09-09T13:28:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)\
**Post date:** [September 9, 2021, 1:41pm UTC](https://discourse.julialang.org/t/error-ran-out-of-registers-during-register-allocation-have-you-ever-seen-this-message/60153/4 "2021-09-09T13:41:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [September 9, 2021, 1:49pm UTC](https://discourse.julialang.org/t/error-ran-out-of-registers-during-register-allocation-have-you-ever-seen-this-message/60153/5 "2021-09-09T13:49:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anon56330260](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@anon56330260](https://discourse.julialang.org/u/anon56330260)\
**Post date:** [September 9, 2021, 2:10pm UTC](https://discourse.julialang.org/t/error-ran-out-of-registers-during-register-allocation-have-you-ever-seen-this-message/60153/6 "2021-09-09T14:10:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)\
**Post date:** [September 9, 2021, 2:35pm UTC](https://discourse.julialang.org/t/error-ran-out-of-registers-during-register-allocation-have-you-ever-seen-this-message/60153/7 "2021-09-09T14:35:27Z")

</div>

[The `mapc()` (i.e. `mapch()`) is a backedge of the `_w`](https://github.com/kimikage/ColorBlendModes.jl/runs/3554787389?check_suite_focus=true#step:5:401).

```llvm
              %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.

---

<div class="post-metadata">

**Author:** ![anon56330260](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@anon56330260](https://discourse.julialang.org/u/anon56330260)\
**Post date:** [September 9, 2021, 2:42pm UTC](https://discourse.julialang.org/t/error-ran-out-of-registers-during-register-allocation-have-you-ever-seen-this-message/60153/8 "2021-09-09T14:42:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)\
**Post date:** [September 9, 2021, 3:19pm UTC](https://discourse.julialang.org/t/error-ran-out-of-registers-during-register-allocation-have-you-ever-seen-this-message/60153/9 "2021-09-09T15:19:45Z")

</div>

> [@anon56330260](#):
>
> 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)

Good catch! By disabling the coverage, the error no longer occurs.  
[https://github.com/kimikage/ColorBlendModes.jl/actions/runs/1217813189](https://github.com/kimikage/ColorBlendModes.jl/actions/runs/1217813189)

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

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

---

<div class="post-metadata">

**Author:** ![anon56330260](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@anon56330260](https://discourse.julialang.org/u/anon56330260)\
**Post date:** [September 9, 2021, 4:31pm UTC](https://discourse.julialang.org/t/error-ran-out-of-registers-during-register-allocation-have-you-ever-seen-this-message/60153/10 "2021-09-09T16:31:33Z")

</div>

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](https://docs.julialang.org/en/v1/devdocs/llvm/#Improving-LLVM-optimizations-for-Julia) and dump all the pass information? So it’s easy to locate the problematic pass.

---

<div class="post-metadata">

**Author:** ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)\
**Post date:** [September 10, 2021, 7:52am UTC](https://discourse.julialang.org/t/error-ran-out-of-registers-during-register-allocation-have-you-ever-seen-this-message/60153/11 "2021-09-10T07:52:28Z")

</div>

xref: [https://github.com/JuliaLang/julia/issues/42200](https://github.com/JuliaLang/julia/issues/42200)
