Skip to content

Avoid monomorphizing intrinsic fallback bodies that the backend does not need #149945

Closed

Description

@RalfJung

Currently, when an intrinsic with a fallback body gets used, we always monomorphize and codegen that body: mono item collection does not know whether the backend will invoke the fallback body or supply its own implementation. This has led to perf regressions in #148478 and possibly elsewhere.

It would be better if the backend could inform mono item collection about intrinsics it will overwrite anyway, so that we can avoid codegen'ing those.

Activity

  1. added
    needs-triage
    on Dec 13, 2025
  2. added
    I-compiletime
    T-compiler
    and removed
    needs-triage
    on Dec 13, 2025
  3. scottmcm commented on Dec 14, 2025

    @scottmcm
    Member

    This information could also be useful in mir-opt: today we never inline any fallback mir since the codegen backend needs to be able to see the call, but if we knew the fallback would be used we could inline it instead (and in practice typically not need to emit them as functions at all).

  4. hanna-kruppe commented on Dec 14, 2025

    @hanna-kruppe
    Contributor

    Do MIR opt passes know for sure which backend will ultimately be used? I thought that optimized MIR that’s encoded in metadata can later be codegen’d by multiple backends in downstream crates.

  5. RalfJung commented on Dec 14, 2025

    @RalfJung
    MemberAuthor

    Yeah, inlining based on the current backend would work well for the LLVM backend but the other backends use the same sysroot so they'd get MIR where fallback bodies might have been inlined that would have had an intrinsic available. We may decide that the LLVM backend is more important so we do this anyway, but it's not a clear win for everyhing.

  6. added a commit that references this issue on Feb 4, 2026
  7. added a commit that references this issue on Feb 4, 2026
  8. added a commit that references this issue on Feb 4, 2026
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

    I-compiletimeT-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions