-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix: no hole in liveranges for pinned vreg move src. #60
Merged
cfallin
merged 1 commit into
bytecodealliance:main
from
cfallin:fix-pinned-vreg-mov-src
Jun 27, 2022
Merged
Bugfix: no hole in liveranges for pinned vreg move src. #60
cfallin
merged 1 commit into
bytecodealliance:main
from
cfallin:fix-pinned-vreg-mov-src
Jun 27, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Right now, pinned vregs are a way of naming real registers (a compatibility shim of sorts for Cranelift's `RealReg`s) and can be used as sources and dests of moves. When the input program does so, regalloc2 converts these into "ghost" uses and defs on the other vreg of the move (dest or source, respectively) with a fixed-register constraint. So `move v128, v0` where `v0` is pinned to `p0` turns into a "ghost def" on `v128` with constraint `fixed p0`. There is some fancy manipulation of liveranges to make this all work while properly recording where the preg's value must be preserved. Unfortunately, there was an off-by-one in the location of the move and transition of live-ranges which interacts poorly with the "implicit live-in" of pinned vregs at function start. As a result, a function body that starts like: ``` move v128, v0 def v9000 move v129, v1 ``` might allocate `p1` (to which `v1` is pinned) for `v9000`. This clobbers the original value. Fortunately this only impacts the implicit live-in, and Cranelift's use of regalloc2 is such that it will always copy all values out of pinned vregs (creating ghost defs) without intervening defs, *except* in the case of `sret` ("structure return") arguments. If a program does not use `sret` arguments (and the `cranelift-wasm` frontend does not), then this bug should not be reachable. Long-term, we really need to kill pinned vregs with fire (bytecodealliance#3); the special cases that arise from these, and from special handling of moves, are too much incidental complexity. All of this can go away once Cranelift migrates all fixed-register cases to operand constraints instead. That will be a happy day. Thanks to @bjorn3 for finding and reporting this issue!
fitzgen
approved these changes
Jun 27, 2022
Merged
cfallin
added a commit
to cfallin/wasmtime
that referenced
this pull request
Jun 27, 2022
cfallin
added a commit
to cfallin/wasmtime
that referenced
this pull request
Jun 27, 2022
alexcrichton
pushed a commit
to bytecodealliance/wasmtime
that referenced
this pull request
Jun 27, 2022
…loc2#60. (#4333) * Upgrade to regalloc2 v0.2.3 to get bugfix from bytecodealliance/regalloc2#60. * Update RELEASES.md. * Update two compile tests based on slightly shifting regalloc output. * Add dividing line in RELEASES.md as per format.
alexcrichton
pushed a commit
to bytecodealliance/wasmtime
that referenced
this pull request
Jun 27, 2022
…loc2#60. (#4335) * Upgrade to regalloc2 v0.2.3 to get bugfix from bytecodealliance/regalloc2#60. * Update RELEASES.md. * Update two compile tests based on slightly shifting regalloc output.
afonso360
pushed a commit
to afonso360/wasmtime
that referenced
this pull request
Jun 30, 2022
…loc2#60. (bytecodealliance#4335) * Upgrade to regalloc2 v0.2.3 to get bugfix from bytecodealliance/regalloc2#60. * Update RELEASES.md. * Update two compile tests based on slightly shifting regalloc output.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Right now, pinned vregs are a way of naming real registers (a
compatibility shim of sorts for Cranelift's
RealReg
s) and can be usedas sources and dests of moves. When the input program does so, regalloc2
converts these into "ghost" uses and defs on the other vreg of the move
(dest or source, respectively) with a fixed-register constraint. So
move v128, v0
wherev0
is pinned top0
turns into a "ghost def"on
v128
with constraintfixed p0
.There is some fancy manipulation of liveranges to make this all work
while properly recording where the preg's value must be preserved.
Unfortunately, there was an off-by-one in the location of the move and
transition of live-ranges which interacts poorly with the "implicit
live-in" of pinned vregs at function start. As a result, a function body
that starts like:
might allocate
p1
(to whichv1
is pinned) forv9000
. This clobbersthe original value.
Fortunately this only impacts the implicit live-in, and Cranelift's use
of regalloc2 is such that it will always copy all values out of pinned
vregs (creating ghost defs) without intervening defs, except in the
case of
sret
("structure return") arguments. If a program does not usesret
arguments (and thecranelift-wasm
frontend does not), then thisbug should not be reachable.
Long-term, we really need to kill pinned vregs with fire (#3); the
special cases that arise from these, and from special handling of moves,
are too much incidental complexity. All of this can go away once
Cranelift migrates all fixed-register cases to operand constraints
instead. That will be a happy day.
Thanks to @bjorn3 for finding and reporting this issue!