Skip to content

Cherry-pick #3934 onto 0.35.x release branch.#4012

Merged
cfallin merged 1 commit into
bytecodealliance:release-0.35.0from
cfallin:cherry-pick-0.35.3-fix
Apr 11, 2022
Merged

Cherry-pick #3934 onto 0.35.x release branch.#4012
cfallin merged 1 commit into
bytecodealliance:release-0.35.0from
cfallin:cherry-pick-0.35.3-fix

Conversation

@cfallin
Copy link
Copy Markdown
Member

@cfallin cfallin commented Apr 11, 2022

This cherry-picks the fix to an instruction-lowering bug that causes a regalloc panic from #3934 onto our 0.35.x branch. The original bug was merged prior to the 0.35.0 release, and we missed that when making the fix (we had thought it was unreleased). This fix will be subsequently released as a new point release (0.35.3).

Addresses #4010.

The `fpcmp` helper in the x64 backend uses `put_in_xmm_mem` for one of
its operands, which allows the compiler to merge a load with the compare
instruction (`ucomiss` or `ucomisd`).

Unfortunately, as we saw in bytecodealliance#2576 for the integer-compare case, this
does not work with our lowering algorithm because compares can be
lowered more than once (unlike all other instructions) to reproduce the
flags where needed. Merging a load into an op that executes more than
once is invalid in general (the two loads may observe different values,
which violates the original program semantics because there was only one
load originally).

This does not result in a miscompilation, but instead will cause a panic
at regalloc time because the register that should have been defined by
the separate load is never written (the load is never emitted
separately).

I think this (very subtle, easy to miss) condition was unfortunately not
ported over when we moved the logic in bytecodealliance#3682.

The existing fcmp-of-load test in `cmp-mem-bug` (from bytecodealliance#2576) does not
seem to trigger it, for a reason I haven't fully deduced. I just added
the verbatim function body (happens to come from `clang.wasm`) that
triggers the bug as a test.

Discovered while bringing up regalloc2 support. It's pretty unlikely to
hit by chance, which is why I think none of our fuzzing has hit it yet.
@cfallin cfallin requested a review from fitzgen April 11, 2022 17:37
@cfallin cfallin merged commit c740e5d into bytecodealliance:release-0.35.0 Apr 11, 2022
@cfallin cfallin deleted the cherry-pick-0.35.3-fix branch April 11, 2022 18:11
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.

2 participants