bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
14.81k stars 1.24k forks source link

winch: Save state before emitting `br_if` #8886

Closed saulecabrera closed 4 days ago

saulecabrera commented 4 days ago

Fixes: https://github.com/bytecodealliance/wasmtime/issues/8848

Similar to all the control instructions, any state must be explicitly saved before emitting the code for br_if.

This commit ensures that live locals and registers are explicilty saved before emitting the code for br_if. Prior to this commit, live locals and registers were not saved every time causing incorrect behavior in cases where the calculation of the conditional argument didn't trigger a spill.

This change introduces the explicit spill after calculating the branch condition argument to minimize memory traffic in case the conditional is already in a register.