cfallin opened PR #3934 from x64-fpcmp-fix
to main
:
The
fpcmp
helper in the x64 backend usesput_in_xmm_mem
for one of
its operands, which allows the compiler to merge a load with the compare
instruction (ucomiss
orucomisd
).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 fromclang.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.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
cfallin requested fitzgen for a review on PR #3934.
cfallin requested abrown for a review on PR #3934.
abrown submitted PR review.
abrown merged PR #3934.
Last updated: Nov 22 2024 at 16:03 UTC