You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After an investigation as to why GCC emits fmadd for #64591, it turns out its because the C language spec allows it and so GCC defaults to -ffp-contract=fast even when ffast-math is off. Clang and MSVC on the other hand default to "off" because it is considered a value changing optimization in the IEEE 754 specification and is therefore considered unsafe.
While we do not use GCC for our own builds, I believe we still have some community provided support for it and this represents a potential issue for certain code patterns that could exist in the JIT. We should likely ensure that fp-contract is consistently set to OFF for all compilers we support.
Activity
ghost added
untriagedNew issue has not been triaged by the area owner
My expectation here is that this is because this did not represent a problem for most x86/x64 apps given that FMA instructions didn't exist until ~2013 when the FMA3 instruction set was added. These instructions were likewise only available if explicitly opting into such codegen support so didn't represent an issue for most compilations (which merely targeted the x64 baseline).
Arm64 however brings fused multiply-add instructions as "baseline" and they are always available. I expect this caused determinism and other hard to track down bugs which forced the default behavior to change.
Thanks for these findings. I agree we should explicitly turn off this option in global configuration. It looks like clang has also turned it on arm as well: llvm/llvm-project#50688. We use -std=gnu99 (for both clang and gcc), which turns on ffp-contract=fast on x64. (if we were using -std=c99 then gcc uses ffp-contract=off)
ps - although it's (currently) x64-only issue, I just wanted to note that some official mono build jobs, such as Build Browser wasm Linux release Runtime_Release (leg which runs on PR) also use GNU toolchain for the entire build.
Activity
tannergooding commentedon Feb 1, 2022
CC. @kunalspathak, @jkotas
tannergooding commentedon Feb 1, 2022
Notably it looks like MSVC only recently changed from
ontooff: https://docs.microsoft.com/en-us/cpp/preprocessor/fp-contract?view=msvc-170My expectation here is that this is because this did not represent a problem for most x86/x64 apps given that FMA instructions didn't exist until ~2013 when the FMA3 instruction set was added. These instructions were likewise only available if explicitly opting into such codegen support so didn't represent an issue for most compilations (which merely targeted the x64 baseline).
Arm64 however brings
fused multiply-addinstructions as "baseline" and they are always available. I expect this caused determinism and other hard to track down bugs which forced the default behavior to change.jkotas commentedon Feb 1, 2022
cc @am11
am11 commentedon Feb 1, 2022
Thanks for these findings. I agree we should explicitly turn off this option in global configuration. It looks like clang has also turned it on arm as well: llvm/llvm-project#50688. We use
-std=gnu99(for both clang and gcc), which turns on ffp-contract=fast on x64. (if we were using-std=c99then gcc uses ffp-contract=off)ps - although it's (currently) x64-only issue, I just wanted to note that some official mono build jobs, such as
Build Browser wasm Linux release Runtime_Release(leg which runs on PR) also use GNU toolchain for the entire build.EgorBo commentedon Feb 1, 2022
It always looked weird to me why we use "fast math" on MSVC (and only for MSVC) for majority of math functions: https://github.com/dotnet/runtime/blob/main/src/coreclr/classlibnative/float/floatdouble.cpp#L13