Skip to content

Handle conflicting Before and After fixed-reg constraints with a copy. - #54

Merged
cfallin merged 7 commits into
bytecodealliance:mainfrom
cfallin:conflicting-fixed-constraints
May 31, 2022
Merged

cfallin merged 7 commits into
bytecodealliance:mainfrom
cfallin:conflicting-fixed-constraints

Conversation

@cfallin

@cfallin cfallin commented May 30, 2022

Copy link
Copy Markdown
Member

This fixes #53. Previously, if two operands on an instruction
specified different vregs constrained to the same physical register
at the Before (Early) and After (Late) points of the instruction, and
the Before was live downward as well, we would panic: we can't insert
a move into the middle of an instruction, so putting the first vreg in
the preg at Early implies we have an unsolveable conflict at Late.

We can solve this issue by adding some new logic to insert a copy, and
rewrite the constraint. This reuses the multi-fixed-reg-constraint
fixup logic. While that logic handles the case where the same vreg
has multiple different fixed-reg constraints, this new logic
handles different vregs with the same fixed-reg constraints, but
at different program points; so the two are complementary.

This addresses the specific test case in #53, and also fuzzes cleanly
with the change to the fuzz testcase generator to generate these
cases (which also immediately found the bug).

cfallin added 2 commits May 30, 2022 12:36
Currently, the fuzz testcase generator will add at most one
fixed-register constraint to an instruction per physical register. This
avoids impossible situations, such as specifying that both `v0` and `v1`
must be placed into the same `p0`.

However, it *should* be possible to say that `v0` is in `p0` before the
instruction, and `v1` is in `p0` after the instruction (i.e., at `Early`
and `Late` operand positions).

This in fact exposes a limitation in the current allocator design: when
`v0` is live downward, with the above constraints, it will result in an
impossible allocation situation because we cannot split in the middle of
an instruction. A subsequent fix will rectify this by using the
multi-fixed-reg fixup mechanism.
This fixes bytecodealliance#53. Previously, if two operands on an instruction
specified *different* vregs constrained to the same physical register
at the Before (Early) and After (Late) points of the instruction, and
the Before was live downward as well, we would panic: we can't insert
a move into the middle of an instruction, so putting the first vreg in
the preg at Early implies we have an unsolveable conflict at Late.

We can solve this issue by adding some new logic to insert a copy, and
rewrite the constraint. This reuses the multi-fixed-reg-constraint
fixup logic. While that logic handles the case where the *same* vreg
has multiple *different* fixed-reg constraints, this new logic
handles *different* vregs with the *same* fixed-reg constraints, but
at different *program points*; so the two are complementary.

This addresses the specific test case in bytecodealliance#53, and also fuzzes cleanly
with the change to the fuzz testcase generator to generate these
cases (which also immediately found the bug).
@cfallin
cfallin requested a review from fitzgen May 30, 2022 19:42
cfallin added 5 commits May 30, 2022 15:19
When the liverange for the defined vreg with fixed constraint at Late is
*merged* with the liverange for the used vreg with fixed constraint at
Early, the strategy of putting a fixed reservation on the preg at Early
fails, because the whole bundle is minimal (if it spans just the
instruction's Early and Late and nothing else). This could happen if
e.g. the def flows into a blockparam arg that merges with a blockparam
defining the used value.

Instead we move the def one halfstep earlier, to the Early point, with
its fixed-reg constraint still in place. This has the same effect but
works when the two are merged.

@fitzgen fitzgen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cfallin
cfallin merged commit 52818a7 into bytecodealliance:main May 31, 2022
@cfallin
cfallin deleted the conflicting-fixed-constraints branch May 31, 2022 21:01
@cfallin cfallin mentioned this pull request May 31, 2022
Amanieu added a commit to Amanieu/regalloc2 that referenced this pull request Nov 19, 2023
These are useful to model fixed registers which should not be reused for
other uses/defs. These were disallowed in bytecodealliance#54, but this was too
conservative.

Fundamentally, the only situation where a preg can be used in multiple
fixed constraints within a single instruction is with an early-use and a
late-def. Anything else is a user error because the live ranges will
overlap.

As such this PR relaxes the operand rewrite from bytecodealliance#54 to only apply in
this specific situation. Fixed-late-use and fixed-early-def operands are
left unchanged.
Amanieu added a commit to Amanieu/regalloc2 that referenced this pull request Nov 19, 2023
These are useful to model fixed registers which should not be reused for
other uses/defs. These were disallowed in bytecodealliance#54, but this was too
conservative.

Fundamentally, the only situation where a preg can be used in multiple
fixed constraints within a single instruction is with an early-use and a
late-def. Anything else is a user error because the live ranges will
overlap.

As such this PR relaxes the operand rewrite from bytecodealliance#54 to only apply in
this specific situation. Fixed-late-use and fixed-early-def operands are
left unchanged.
Amanieu added a commit to Amanieu/regalloc2 that referenced this pull request Nov 28, 2023
These are useful to model fixed registers which should not be reused for
other uses/defs. These were disallowed in bytecodealliance#54, but this was too
conservative.

Fundamentally, the only situation where a preg can be used in multiple
fixed constraints within a single instruction is with an early-use and a
late-def. Anything else is a user error because the live ranges will
overlap.

As such this PR relaxes the operand rewrite from bytecodealliance#54 to only apply in
this specific situation. Fixed-late-use and fixed-early-def operands are
left unchanged.
Amanieu added a commit to Amanieu/regalloc2 that referenced this pull request Dec 6, 2023
These are useful to model fixed registers which should not be reused for
other uses/defs. These were disallowed in bytecodealliance#54, but this was too
conservative.

Fundamentally, the only situation where a preg can be used in multiple
fixed constraints within a single instruction is with an early-use and a
late-def. Anything else is a user error because the live ranges will
overlap.

As such this PR relaxes the operand rewrite from bytecodealliance#54 to only apply in
this specific situation. Fixed-late-use and fixed-early-def operands are
left unchanged.
elliottt pushed a commit that referenced this pull request Dec 6, 2023
These are useful to model fixed registers which should not be reused for
other uses/defs. These were disallowed in #54, but this was too
conservative.

Fundamentally, the only situation where a preg can be used in multiple
fixed constraints within a single instruction is with an early-use and a
late-def. Anything else is a user error because the live ranges will
overlap.

As such this PR relaxes the operand rewrite from #54 to only apply in
this specific situation. Fixed-late-use and fixed-early-def operands are
left unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants