-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Arm64: Prefer fmul and fadd/fsub to fmadd/fnmsub #64591
Comments
Tagging subscribers to this area: @JulieLeeMSFT Issue Detailspublic static double calculate1(double x, double y, double z) => x * y - z;
public static double calculate2(double x, double y, double z) => x * y + z; Today we generate 2 instructions G_M29028_IG02: ;; offset=0008H
1E610800 fmul d0, d0, d1
1E622800 fadd d0, d0, d2 godbolt: https://godbolt.org/z/Trrjq9cGs
|
@kunalspathak, this is not a safe/legal optimization to do by default and we should close the issue.
|
There have been many proposals over the years to add some The most obvious way I've considered is via an attribute + flags that allow control over the floating-point behavior for a given method. This would allow it to enable or disable specific sets of All in all, it is not a trivial area and would need some decent design work and buy off before we could implement it. It would potentially be a good feature for dotnet/runtimelab |
For reference, https://godbolt.org/z/o54bYfPbP shows that Clang and MSVC only allow this when specifying Ultimately this comes down to wording in the C language spec that allows this behavior as it leaves contraction up to the implementation. GCC allows it by default while Clang/MSVC do not as it is not an IEEE 754 compliant optimization (it is considered a "value changing" optimization). |
Thanks @tannergooding for the insights. I will close this issue for now. |
Today we generate 2 instructions
fmul
andfadd
and instead should generatefmadd
. Likewise, forfmul
,fsub
.godbolt: https://godbolt.org/z/Trrjq9cGs
The text was updated successfully, but these errors were encountered: