-
Notifications
You must be signed in to change notification settings - Fork 786
Some notes about addisonal simple optimizations for f32/f64 #1911
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
Comments
There are explicit tests in the spec repo that disallow these transformations, see https://github.com/WebAssembly/spec/blob/master/test/core/float_exprs.wast. |
@binji Hmm, may I ask why this all legalized for LLVM but not for wasm?
|
Also LLVM based compilers as Rust and emscripten produce: get_local $p0
f64.neg for |
Hmm, why? E.g. if |
@kripken Good catch, looks like I meant another expression. Remove that |
Sorry, was on vacation. The difference is that the nan bitpattern changes. |
@binji I understand this. But I wondering is it necessary skip this optimizations for LLVM-backed compilers when they targeting to Wasm as well? |
No, the user of LLVM is operating with a different set of assumptions. If they care about nan bitpatterns, they know that they can't use LLVM for this (at least by default). |
Wow. This is unexpected! |
Would it be viable to make it an optional pass that a user must run explicitly? For instance, we have a discussion over at AssemblyScript to eventually add a compiler flag that emits deterministic code exclusively, but it seems that unless this flag is set, doing such optimizations would be fine. |
Yes, I think an optional pass could do optimizations like these that are unsafe in general, but valid for some compiler. Another option is to add a pass option, like "don't care about nan bits" - then existing passes can check that and behave accordingly. Sort of like the existing --ignore-implicit-traps. |
Other possible optimization for floats found on n-body bench: function div(x: f64): f64 {
return -x / 1000.0;
} currently produce: (func $div (export "div") (type $t0) (param $p0 f64) (result f64)
get_local $p0
f64.neg
f64.const 0x1.f4p+9 (;=1000;)
f64.div) but optimal: (func $div (export "div") (type $t0) (param $p0 f64) (result f64)
get_local $p0
f64.const -0x1.f4p+9 (;=-1000;)
f64.div) |
a *= -1
toa = -a
Actual:
Expected:
x * (1 / x)
=>x / x
orx * (1 / y)
=>x / y
Actual:
Expected:
-x / 1000
Actual:
Expected:
The text was updated successfully, but these errors were encountered: