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
{{ message }}
Repository navigation
Avoid monomorphizing intrinsic fallback bodies that the backend does not need #149945
I-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
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.
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).
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.
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.
I-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
scottmcm commentedon Dec 14, 2025
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).
hanna-kruppe commentedon Dec 14, 2025
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.
RalfJung commentedon Dec 14, 2025
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.
Auto merge of #150605 - RalfJung:fallback-intrinsic-skip, r=mati865
Rollup merge of rust-lang#150605 - RalfJung:fallback-intrinsic-skip, …
Auto merge of #150605 - RalfJung:fallback-intrinsic-skip, r=mati865
Auto merge of #150605 - RalfJung:fallback-intrinsic-skip, r=mati865
Auto merge of #150605 - RalfJung:fallback-intrinsic-skip, r=mati865
Auto merge of #150605 - RalfJung:fallback-intrinsic-skip, r=mati865
Auto merge of #150605 - RalfJung:fallback-intrinsic-skip, r=mati865
Auto merge of #150605 - RalfJung:fallback-intrinsic-skip, r=mati865
Auto merge of #150605 - RalfJung:fallback-intrinsic-skip, r=mati865
Auto merge of #150605 - RalfJung:fallback-intrinsic-skip, r=mati865
Auto merge of #150605 - RalfJung:fallback-intrinsic-skip, r=mati865
Auto merge of #150605 - RalfJung:fallback-intrinsic-skip, r=mati865