Skip to content

Impossible constraints when a def and use have same fixed-reg constraint and use is live-out #53

Closed

Description

@mchesser

regalloc2 crashes with: 'Could not allocate minimal bundle, but the allocation problem should be possible to solve', regalloc2-0.2.0/src/ion/process.rs:1006:17

It seems to be related to 128-bit multiplication when targeting x86_64. The following is a manually reduced test-case:

function %regalloc_crash(i64, i64, i64) {
block0(v0: i64, v1: i64, v2: i64):
    v3 = uextend.i128 v1
    v4 = uextend.i128 v2

    v5 = imul.i128 v3, v4
    store.i128 v5, v0

    store.i64 v1, v0
    return
 }

Potentially related to #19 but continues to crash with the latest version.

Activity

  1. changed the title [-]Could not allocate minimal bundle panic[/-] [+]Impossible constraints when a def and use have same fixed-reg constraint and use is live-out[/+] on May 30, 2022
  2. cfallin commented on May 30, 2022

    @cfallin
    Member

    Thanks @mchesser ! I just took a look at this and it is indeed a bug. Fortunately (or unfortunately, depending on perspective), I think Cranelift only hits the conditions necessary for it when lowering a 128-bit multiply here, so it is not exposed upward to Wasmtime; so this isn't going to trigger a point-release. That explains why fuzzing hasn't caught it as well.

    The basic issue is that an input vreg and an output vreg to one instruction are both constrained to the same preg. So we have:

        v0
        |
        |_ fixed(p0)   BEFORE
        |                    mul instruction
        |   _fixed(p0) AFTER
        |  |
        |   v1
        :  :
        :  :
    

    The liverange for v0 needs to split just after the fixed(p0) constraint, i.e. just after the Before progpoint. But for a number of other reasons (mainly that we can't insert moves in the middle of instructions!), splits are always "rounded" to the nearest point between instructions. So the LR for v0 is split after the inst, and this conflicts with the fixed(p0) constraint on v1, and we are stuck (so we hit the assert).

    I suppose we've never had an instance before of two separate vregs constrained to the same preg at the before- and after-points of a single instruction, so we haven't realized this issue yet.

    Probably the best way around this is to use the multi-fixed-reg fixup mechanism to insert a copy if we see that (i) the liverange of a fixed constraint at an use at Before is still live downward, (ii) there is another fixed constraint using the same register at After. I'll play with this a bit.

    Thanks again for the report!

  3. cfallin commented on May 30, 2022

    @cfallin
    Member

    Also a quick note from investigation just now: the RA2-level fuzz testcase generator ensures that only one constraint exists for a given fixed reg, which is why we didn't find this in RA2 fuzzing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions