Open Bug 1849761 Opened 2 years ago Updated 2 years ago

Optimize return_call where target is the same function in Ion

Categories

(Core :: JavaScript: WebAssembly, enhancement, P2)

enhancement

Tracking

()

People

(Reporter: yury, Unassigned)

References

(Blocks 1 open bug)

Details

There is very popular use case (especially for examples and benchmarks) where the function performs the return_call to itself. I'm thinking it will be small effort to add peephole optimization to replace MWasmReturnCall to itself with direct edge/jump after prologue.

Severity: -- → N/A
Priority: -- → P2

I guess this could be done as a simple MIR->MIR transformation pass, applied
only to functions that we know have return_calls. For a function with N
parameters, we'd need to add N phi nodes that sit in between the N
MWasmParameter nodes and the uses of those values. Then convert each
return_call back to the function into a jump to the block holding the phi
nodes, and add (MDefinition*) arguments to the phi node that are the
MDefinitions*s that were the arguments to the return_call. Other details that
come to mind:

  • it might also be necessary to mark the edge on this jump to be a loop
    backedge

  • MIR loops require having the loop body blocks be contiguous. Maybe that
    isn't a problem since the loop body would be the the entire original
    function anyway.

  • Doing this during wasm->MIR conversion would be difficult because we would
    need to know whether to generate the phi nodes before we knew whether we
    actually needed them -- they would only be needed if the function did
    contain return_calls to itself, but since wasm->MIR conversion is
    single-pass, we don't know that until we find such a call.

  • Following experience from bug 1868521 (inlining experimentation), it is a
    bit difficult to find all the MDefinition*s that are the arguments to a
    function, since arguments passed in registers are handled differently from
    those passed on the stack. (But it is possible.) Also, for arguments
    passed on the stack, we would need to remove the MWasmStackArg nodes "left
    behind" after doing this transformation -- not difficult, but an important
    detail.

You need to log in before you can comment on or make changes to this bug.
OSZAR »