Skip to content

Wasm2JS redundant x + 0 operations #13362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
juj opened this issue Jan 28, 2021 · 3 comments
Open

Wasm2JS redundant x + 0 operations #13362

juj opened this issue Jan 28, 2021 · 3 comments
Labels

Comments

@juj
Copy link
Collaborator

juj commented Jan 28, 2021

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

  $3 = (.6666666666666666 - $2) * 6 + 0;
   $3 = $2 * 6 + 0;
  $3 = (.6666666666666666 - $2) * 6 + 0;
   $3 = $2 * 6 + 0;
  $3 = (.6666666666666666 - $0) * 6 + 0;
   $3 = $0 * 6 + 0;

It seems that it would be feasible to optimize away those + 0 additions.

@juj
Copy link
Collaborator Author

juj commented Jan 28, 2021

Looks like Closure does not optimize these away:

  d = (.6666666666666666 - c) * 6 + 0;
   d = a * 6 + 0;

@kripken
Copy link
Member

kripken commented Jan 29, 2021

I think there are issues with negative zero that prevent it:

$ node
Welcome to Node.js v15.6.0.
Type ".help" for more information.
> -0.0 + 0
0
> -0.0 + -0.0
-0
> 0 + -0.0
0

It is valid to remove + -0.0 but not + 0.0, and binaryen does that. However, I think in fastMath we could do both, but we don't atm:

https://github.com/WebAssembly/binaryen/blob/89b811699b2db0c0e2ad744a1240f6283f8eed86/src/passes/OptimizeInstructions.cpp#L1826-L1833

@stale
Copy link

stale bot commented Apr 16, 2022

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.

@stale stale bot added the wontfix label Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants