Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Ensure we set -ffp-contract=off on GCC #64604

Closed

Description

@tannergooding

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

  1. ghost added
    untriaged
    on Feb 1, 2022
  2. tannergooding commented on Feb 1, 2022

    @tannergooding
    MemberAuthor
  3. tannergooding commented on Feb 1, 2022

    @tannergooding
    MemberAuthor

    Notably it looks like MSVC only recently changed from on to off: https://docs.microsoft.com/en-us/cpp/preprocessor/fp-contract?view=msvc-170

    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.

  4. jkotas commented on Feb 1, 2022

    @jkotas
    Member
  5. added
    area-Infrastructure-coreclr
    on Feb 1, 2022
  6. am11 commented on Feb 1, 2022

    @am11
    Member

    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.

  7. EgorBo commented on Feb 1, 2022

    @EgorBo
    Member

    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

  8. ghost added
    in-pr
    on Feb 5, 2022
  9. ghost removed
    in-pr
    on Feb 7, 2022
  10. ghost locked as resolved and limited conversation to collaborators on Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Infrastructure-coreclruntriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions