Skip to content

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

Closed
@hanna-kruppe

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.

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