emscripten-core / emscripten-core/emscripten

Wasm2JS missed optimization opportunity on memset like repeated heap assignments

Open
#13,363 2 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.