Skip to content

Simplify u128->f32 casts thanks to LLVM r334777 #51872

Closed

Description

@hanna-kruppe

This issue tracks two improvements we can make to our codegen after some LLVM updates, to avoid them being buried in a closed issue.

As @nikic pointed out, https://reviews.llvm.org/D47807 defines overflow in u128->f32 casts as resulting in infinity. With that patch, we don't need to manually emit the "is the u128 >= f32::MAX + 0.5 ULP?" check as we currently do and can go back to just emitting a simple uitofp (as we have always done for {u8,u16,u32,u64} -> float casts). However, because of our policy of supporting older LLVM versions, there are actually two steps we can take here at different times:

  • At any time we can backport the patch to our LLVM fork, and skip emitting the check only if compiling with our fork
  • Once we drop support for all LLVM versions that don't have this patch (if I'm not mistaken, it would first be released in LLVM 7), remove our special handling of u128->f32 casts altogether

The latter is honestly the more important step. I doubt there is any significant code size or performance impact from the extra check, but it would be nice to get rid of the tricky code in rustc that is required to implement it.

Activity

  1. added
    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jun 28, 2018
  2. bjorn3 commented on Sep 7, 2019

    @bjorn3
    Member

    Is it already defined on the lowest supported LLVM version?

  3. hanna-kruppe commented on Sep 7, 2019

    @hanna-kruppe
    ContributorAuthor

    It's in LLVM 7 but we still support LLVM 6 right now.

  4. hanna-kruppe commented on Dec 3, 2019

    @hanna-kruppe
    ContributorAuthor

    #66973 bumps our minimum LLVM version to 7 so once that's landed we can do this.

  5. added a commit that references this issue on Dec 15, 2019
    6ad0b55
  6. added 2 commits that reference this issue on Dec 17, 2019
    e8ab2fd
    c4fba08
  7. added 3 commits that reference this issue on Dec 19, 2019
    3d21aa6
    85db539
    efd31c2
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

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions