Repository navigation
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-craneliftThings relevant to the [future] cranelift backendThings relevant to the [future] cranelift backendA-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.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.
Description
$ rustc foo.rs --crate-type lib --emit mir -Cpanic=abortfn map(x: Option<Box<()>>) -> Option<Box<()>> {
match x {
None => None,
Some(x) => Some(x),
}
}// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn map(_1: std::option::Option<std::boxed::Box<()>>) -> std::option::Option<std::boxed::Box<()>> {
debug x => _1; // in scope 0 at a.rs:1:8: 1:9
let mut _0: std::option::Option<std::boxed::Box<()>>; // return place in scope 0 at a.rs:1:31: 1:46
let mut _2: isize; // in scope 0 at a.rs:3:9: 3:13
let _3: std::boxed::Box<()>; // in scope 0 at a.rs:4:14: 4:15
let mut _4: std::boxed::Box<()>; // in scope 0 at a.rs:4:25: 4:26
let mut _5: isize; // in scope 0 at a.rs:6:1: 6:2
scope 1 {
debug x => _3; // in scope 1 at a.rs:4:14: 4:15
}
bb0: {
_2 = discriminant(_1); // bb0[0]: scope 0 at a.rs:3:9: 3:13
switchInt(move _2) -> [0isize: bb3, 1isize: bb1, otherwise: bb2]; // bb0[1]: scope 0 at a.rs:3:9: 3:13
}
bb1: {
StorageLive(_3); // bb1[0]: scope 0 at a.rs:4:14: 4:15
_3 = move ((_1 as Some).0: std::boxed::Box<()>); // bb1[1]: scope 0 at a.rs:4:14: 4:15
StorageLive(_4); // bb1[2]: scope 1 at a.rs:4:25: 4:26
_4 = move _3; // bb1[3]: scope 1 at a.rs:4:25: 4:26
((_0 as Some).0: std::boxed::Box<()>) = move _4; // bb1[4]: scope 1 at a.rs:4:20: 4:27
discriminant(_0) = 1; // bb1[5]: scope 1 at a.rs:4:20: 4:27
StorageDead(_4); // bb1[6]: scope 1 at a.rs:4:26: 4:27
StorageDead(_3); // bb1[7]: scope 0 at a.rs:4:27: 4:28
goto -> bb4; // bb1[8]: scope 0 at a.rs:2:5: 5:6
}
bb2: {
unreachable; // bb2[0]: scope 0 at a.rs:2:11: 2:12
}
bb3: {
discriminant(_0) = 0; // bb3[0]: scope 0 at a.rs:3:17: 3:21
goto -> bb4; // bb3[1]: scope 0 at a.rs:2:5: 5:6
}
bb4: {
_5 = discriminant(_1); // bb4[0]: scope 0 at a.rs:6:1: 6:2
return; // bb4[1]: scope 0 at a.rs:6:2: 6:2
}
}The _5 = discriminant(_1); doesn't have any effect.
(Labeling A-cranelift because this prevents codegen of the goto -> bb4 like return. Which may result in a few extra instructions being emitted to move registers and jump to the return block for cg_clif.)
@rustbot modify labels: +A-mir +A-mir-opt +A-cranelift
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-craneliftThings relevant to the [future] cranelift backendThings relevant to the [future] cranelift backendA-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.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.
Activity
jonas-schievink commentedon Mar 29, 2020
We already have a pass that propagates the
unreachableterminator, it should be possible to make it handlereturnas well.(however
returncan leave sideeffects visible to the caller, so maybe this should be a proper dead code elimination pass instead)ecstatic-morse commentedon Mar 29, 2020
For background, this is a side-effect of #68528 (see the MIR diagram in the PR summary) and #68943. The MIR for the above example used to contain a frivolous open drop of
x. After my changes to drop elaboration, all branches of the open drop become no-opGotos, which are then removed by theSimplifyCfgpass. The read of the discriminant as part of the open drop remains, however.To my knowledge, we don't have a dead-code elimination pass for the MIR, which would be the proper way to handle this.
Rollup merge of rust-lang#70595 - wesleywiser:remove_unused_discrimin…
Rollup merge of rust-lang#70595 - wesleywiser:remove_unused_discrimin…