Skip to content

[WebAssembly] __table_base should not be optimized into locals (wasm locals or stack locals) #138861

@mf-RDP

Description

@mf-RDP

__table_base is currently defined as a non mutable global. However, think of a specific implementation that works with BOTH native and wasm (integer) function pointers - just as an example.

For global_get & global_set, their implementations could do complex modifications of the returned value (mimicked __table_base) in conjunction with call_indirect.

This works well, I did actually implement such a thing.

However, it gets broken by the following compiler optimization:
global_get(__table_base)
local_tee(42) <<<<---
i32_add(142)
call_indirect()
local_get(42)
i32_add(143)
call_indirect()

I think, as __table_base can be a highly sophisticated, implementation specific thing, it would be good not to intern it into locals.

the code above should best look like this
global_get(__table_base)
i32_add(142)
call_indirect()
global_get(__table_base) <<<<---
i32_add(143)
call_indirect()

I would say that introduced overhead is none, or absolutely minimal.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions