Skip to content

Local variables are not the most efficient way to use values multiple times. #4

Open
@ghost

Description

The PushPop document notes:

'However, push/pop are representing expression tree edges in WebAssembly, which can only have a single definition and a single use. The way to use a value multiple times in WebAssembly is to use set_local and get_local.'

However a single definition value used multiple times within it's lexical scope is more efficiently kept on the values stack and referenced from there as proposed in WebAssembly#685

In a single pass compiler a value kept on the blocks values stack is known to no longer be live at the end of the block which helps the compiler with register allocation, whereas if a local variable is used the compiler may not know this until much later when there is another write to the variable.

An expressionless encoding in which there was no values stack was explored and while possible it leads to more local variables than necessary and this slows decoding. At the other extreme it may well be possible to eliminate local variables and this might lead to even faster and simpler decoding to SSA form.

So I strongly dispute the assertion that local variable are 'the way to use a value multiple times in WebAssembly', rather this is just one known poor option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions