-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-mir-optArea: MIR optimizationsArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
I got excited by and went to try out SimplifyArmIdentity
+SimplifyBranchSame
from #66282, but was surprised that the first thing I attempted didn't actually get optimized away as I'd expected.
pub fn demo(x: Result<u32, i32>) -> Result<u32, i32> {
match x {
Ok(v) => Ok(v),
Err(e) => Err(e),
}
}
Repro: https://rust.godbolt.org/z/bxFAsP
It does, however, optimize away in MIR with -Z mir-opt-level=2
.
(Note that this is the simple case without ?
, where there are no function calls involved so inlining should be irrelevant.)
Seems like there's a gap here? cc @Centril @oli-obk @wesleywiser
Some guesses from the discord conversation where centril asked me to open this issue: the Storage{Live|Dead}
presence, extra copies because [ui]32
, const prop hiding something, ...
Metadata
Metadata
Assignees
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-mir-optArea: MIR optimizationsArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.