Stream: cranelift

Topic: Could regalloc3 eliminate those spills?


view this post on Zulip primoly (Dec 06 2024 at 20:08):

Hello. Could regalloc3 solve this issue with rematerialisation? I have this branch using regalloc3 as the backend for regalloc2 (just a more up to date variant of this) and then use it in Wasmtime/Cranelift. But since regalloc2 does not support rematerialisation, the regalloc3.rs implementation for can_rematerialize always returns None. If Cranelift where to use regalloc3 directly and implemented can_rematerialize properly, would that solve, for instance, the issue of unneeded spills here?

New register allocator designed as a successor to regalloc2 - Amanieu/regalloc3
Test Cases case.zip Steps to Reproduce Hi, I run the attached two cases(good.wasm & bad.wasm) in Wasmtime and WasmEdge(AOT), and collect their execution time respectively (measured by time tool). #...
A new register allocator. Contribute to primoly/regalloc2 development by creating an account on GitHub.
A new register allocator. Contribute to Amanieu/regalloc2 development by creating an account on GitHub.
A new register allocator. Contribute to primoly/regalloc2 development by creating an account on GitHub.

view this post on Zulip Amanieu (Dec 06 2024 at 20:34):

Yes, regalloc3 will never spill a rematerializable value. However it would still requires that Cranelift provide this information to the register allocator.

New register allocator designed as a successor to regalloc2 - Amanieu/regalloc3

view this post on Zulip Chris Fallin (Dec 06 2024 at 20:55):

For anyone interested in this -- the path toward experimenting directly with RA3 by porting Cranelift onto its APIs would be:

My PR to move to RA2 (https://github.com/bytecodealliance/wasmtime/pull/3989) is an upper bound for effort: it shows what it takes to lift the whole compiler onto a new set of types, but also involved refactors for RA2's SSA-based VCode. Nevertheless expect the diff to be nontrivial.

If all that work is done, then there would be some process questions around maintenance and vetting and code-review -- RA2 was fully code-reviewed and vetted per BA standards, and we would need to do the same for RA3 -- and we'd want more of the Cranelift team to be familiar with RA3 as well since the regalloc is a critical piece of the backend. But all those things would come after a "direct port" prototype showing benefits.

This is a draft PR for now, meant to serve as a discussion-starter. I'll work on splitting this into logically separate commits next week, but wanted to get the initial thing up first. All test...

Last updated: Dec 23 2024 at 12:05 UTC