bytecodealliance / wasmtime

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

Merge blocks in `cranelift-frontend` and/or the mid-end #8788

Open fitzgen opened 3 weeks ago

fitzgen commented 3 weeks ago

When a block has only a single, unconditional predecessor, we should merge it into its predecessor. We see this relatively frequently due to the way that cranelift-wasm creates blocks (which can certainly be improved, but I think can't fully solve this issue).

One option is to do this during CLIF construction in cranelift-frontend when we call seal_block, as that is when we are declaring that all predecessors for a block have been linked up.

Another option is to do this somewhere in the mid-end, either when building the e-graph or when elaborating out of it.

We might want to do both, since legalization can also introduce new blocks.