alexcrichton opened PR #12369 from alexcrichton:fix-lower-fmla to bytecodealliance:main:
This commit refactors the x64 and aarch64 backends to no longer have recursion in the lowering of the
fmaCLIF instruction. These internally usedfnegof an operand to switch back-and-forth between two native instructions, but that meant that unoptimized code could control recursion in the backend. The rules additionally weren't necessary since egraphs already optimize away extrafnegnodes meaning that the backends just need to match a single layer.I found that I couldn't actually trigger stack overflow in a release build of Wasmtime for either backend. Upon looking at the generated machine code it looks like the constructors here were tail-recursive which prevented the stack overflow. Nonetheless there's no need for this recursion to exist, and in debug mode it definitely blows the stack.
The two backends are now more similar in structure than they were before, but the meaning of similarly-named functions is different between the two backends to match the native behavior of the generated instructions.
Closes #12368
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested cfallin for a review on PR #12369.
alexcrichton requested wasmtime-compiler-reviewers for a review on PR #12369.
github-actions[bot] added the label cranelift on PR #12369.
github-actions[bot] added the label cranelift:area:x64 on PR #12369.
github-actions[bot] added the label cranelift:area:aarch64 on PR #12369.
cfallin submitted PR review:
Thanks!
Could we add ISA tests that have a bunch of nested fnegs, and show compilation with and without opts enabled (similar to #12333)?
cfallin created PR review comment:
This is still breaking my brain somewhat -- "then subtract" is ambigous (this reads like
result = accum - (-(a*b))). Could we write the formula? E.g.result = -(a*b) - accum.(likewise for others)
alexcrichton updated PR #12369.
alexcrichton updated PR #12369.
alexcrichton has enabled auto merge for PR #12369.
alexcrichton added PR #12369 x64/aarch64: Remove recursion in fma backend rules to the merge queue.
github-merge-queue[bot] removed PR #12369 x64/aarch64: Remove recursion in fma backend rules from the merge queue.
alexcrichton added PR #12369 x64/aarch64: Remove recursion in fma backend rules to the merge queue.
alexcrichton merged PR #12369.
alexcrichton removed PR #12369 x64/aarch64: Remove recursion in fma backend rules from the merge queue.
Last updated: Jan 29 2026 at 13:25 UTC