-
Notifications
You must be signed in to change notification settings - Fork 821
fast-math: Fold float multiplication by minus one to unary negative #3189
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
Conversation
| double value; | ||
| if (fastMath && | ||
| matches(curr, binary(Abstract::Sub, any(), fval(&value))) && | ||
| if (matches(curr, binary(Abstract::Sub, any(), fval(&value))) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also removed fastMath guard from here to allow canonicalize x - (-0.0) ==> x + 0.0 which is always safe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kripken what was the verdict here? I thought we had decided this wasn't safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is safe as we do still have an operation - we just replace an add with a subtract, and they should have the same impact on NaN bits. Also, I don't think making the constant negative makes a difference. So this looks ok to me.
I'd recommend verifying this with another data point, like running the wasm before and after this opt in V8, and seeing that indeed all is as expected. That would prevent the fuzzer from finding a problem later - and since it can detect this, if it can't find a problem, I think we're ok.
|
Fuzzed: |
tlively
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The transformation itself looks good, but I'm not so sure about the other changes.
| double value; | ||
| if (fastMath && | ||
| matches(curr, binary(Abstract::Sub, any(), fval(&value))) && | ||
| if (matches(curr, binary(Abstract::Sub, any(), fval(&value))) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kripken what was the verdict here? I thought we had decided this wasn't safe.
tlively
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
This is WebAssembly fiddle which compare different variant of subtractions NaN (quiet, signal, arithm, non-canonical, signed and unsigned) and negative zero with similar but optimized version: https://webassembly.studio/?f=fs4kfeplvgb On Chrome 85. All transforms valid. |
After #3155 we could add more NaN-sign sensitive simplifications for float operations.
x * -1.0->-x(fneg(x))