Stream: git-wasmtime

Topic: wasmtime / PR #3934 x64 backend: fix fpcmp to avoid load-...


view this post on Zulip Wasmtime GitHub notifications bot (Mar 16 2022 at 03:57):

cfallin opened PR #3934 from x64-fpcmp-fix to main:

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 #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 #3682.

The existing fcmp-of-load test in cmp-mem-bug (from #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.

<!--

Please ensure that the following steps are all taken care of before submitting
the PR.

Please ensure all communication adheres to the code of conduct.
-->

view this post on Zulip Wasmtime GitHub notifications bot (Mar 16 2022 at 03:57):

cfallin requested fitzgen for a review on PR #3934.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 16 2022 at 03:57):

cfallin requested abrown for a review on PR #3934.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 16 2022 at 18:16):

abrown submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 16 2022 at 18:16):

abrown merged PR #3934.


Last updated: Dec 23 2024 at 13:07 UTC