emilk / emilk/eframe_template

`wasm-opt` failes to optimize in some cases

Open
#213 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.2k
Forks
230
Avg merge
11m
Merged PRs (30d)
1

Description

This issue is for explaining the reason we need each flag I added in #191

Also see: https://github.com/trunk-rs/trunk/issues/866

### optional WASM feature of wasm-opt

There are wasm features that `wasm-opt` does not support by default, including:

- `--enable-bulk-memory` is for `memcpy` like instructtions: `memory.copy`, `memory.fill`, ...[^0]
- `--enable-nontrapping-float-to-int` provides _sat variants of `ixx.trunc_fxx_s` [^1]
- `--enable-threads` enables atomic operations. WASM is currently single-threaded though

LLVM used the `_sat` for its [`fp_to_sint_sat`](https://github.com/llvm/llvm-project/blob/d406c15fc8fc84efe8f7fd073afe64b21974e2c1/llvm/lib/Target/WebAssembly/WebAssemblyInstrConv.td#L100)

A empty repo (whether added poll_promise) will compile with trunk under release mode fine, but once one of them are involved, we must provide such options.

I'm trying to write a minimum reproduce code, but it's hard to know how to make the assembly result contain specific instruction without naked asm.

This also depends on LLVM version, because `rustc` compiles to LLVM IR.

For my rustc 1.93 and [doukutsu-save-editor](https://github.com/mokurin000/doukutsu-save-editor-rs), I found `--enable-threads` can be removed, but `--enable-bulk-memory` and `--enable-nontrapping-float-to-int` were used

Looking into LLVM source code, the wasm memcpy was defined as [`CPY_A#B`](https://github.com/llvm/llvm-project/blob/d406c15fc8fc84efe8f7fd073afe64b21974e2c1/llvm/lib/Target/WebAssembly/WebAssemblyInstrBulkMemory.td#L85C6-L85C13), [`COPY_A#B`](https://github.com/llvm/llvm-project/blob/d406c15fc8fc84efe8f7fd073afe64b21974e2c1/llvm/lib/Target/WebAssembly/WebAssemblyInstrBulkMemory.td#L58-L64), etc.

And to determine whether it's being used, see [llvm frontend code](https://llvm.org/doxygen/WebAssemblyISelLowering_8cpp_source.html), and look.up for `COPY_I32`, `COPY_I64`.

[^0]: https://github.com/WebAssembly/spec/blob/main/proposals/bulk-memory-operations/Overview.md
[^1]: https://github.com/WebAssembly/spec/blob/main/proposals/nontrapping-float-to-int-conversion/Overview.md

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.