emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.39k stars 3.26k forks source link

Wasm2JS redundant asm.jsism #13364

Open juj opened 3 years ago

juj commented 3 years ago

Building juj/wasm_webgpu@4c2600b clear_screen sample for testing WebGPU on Wasm2JS, I notice the following kind of statements appear:

function ObtainedWebGpuAdapter($0, $1) {
 $0 = $0 | 0;
 $1 = $1 | 0;
 $1 = __stack_pointer - 80 | 0;
 __stack_pointer = $1;
 HEAP32[282] = $0;
 memcpy($1 + 8 | 0);
 wgpu_adapter_request_device_async($0 | 0, $1 + 8 | 0, 2, 0);
 __stack_pointer = $1 + 80 | 0;
}

There are these asm.js style $0 = $0 | 0; and $1 = $1 | 0; statements, which do not go away with closure:

function R(a, b) {
 a = a | 0;
 b = b | 0;
 b = M - 80 | 0;
 M = b;
 e[282] = a;
 P(b + 8 | 0);
 G(a | 0, b + 8 | 0, 2, 0);
 M = b + 80 | 0;
}

Here

 $1 = $1 | 0;
 $1 = __stack_pointer - 80 | 0;

is redundant, the $1 = $1 | 0; part could be dropped. Also applying the missed optimization #13363 could give

 __stack_pointer = $1 = __stack_pointer - 80 | 0;

Then again

 wgpu_adapter_request_device_async($0 | 0, $1 + 8 | 0, 2, 0);

looks redundant, $0 is already i32, so would not need coerced again (and the callee prelude will also coerce it once more)

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.