emscripten-core / emscripten-core/emscripten
Wasm2JS missed optimization opportunity on memset like repeated heap assignments
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 109
Description
Building https://github.com/juj/wasm_webgpu/commit/4c2600b0f6549f95fe9251cba629c935fbc74ba8 clear_screen sample for testing WebGPU on Wasm2JS, I notice the following kind of statements appear:
```js
HEAP32[$1 + 40 >> 2] = 0;
HEAP32[$1 + 44 >> 2] = 0;
HEAP32[$1 + 32 >> 2] = 0;
HEAP32[$1 + 36 >> 2] = 0;
HEAP32[$1 + 24 >> 2] = 0;
HEAP32[$1 + 28 >> 2] = 0;
HEAP32[$1 + 16 >> 2] = 0;
HEAP32[$1 + 20 >> 2] = 0;
HEAP32[$1 + 8 >> 2] = 0;
HEAP32[$1 + 12 >> 2] = 0;
```
These look like unrolled `-O3` memset code. That code could be simplified as
```js
HEAP32[$1 + 40 >> 2] = HEAP32[$1 + 44 >> 2] = HEAP32[$1 + 32 >> 2] = HEAP32[$1 + 36 >> 2] = HEAP32[$1 + 24 >> 2] = HEAP32[$1 + 28 >> 2] = HEAP32[$1 + 16 >> 2] = HEAP32[$1 + 20 >> 2] = HEAP32[$1 + 8 >> 2] = HEAP32[$1 + 12 >> 2] = 0;
```
Contributor guide
Assessment
This issue has not been assessed yet.