Skip to content

Commit 6de6d70

Browse files
committed
Modify SimplifyArmIdentity so it can trigger on mir-opt-level=1
I also added test cases to make sure the optimization can fire on all of these cases: ```rust fn case_1(o: Option<u8>) -> Option<u8> { match o { Some(u) => Some(u), None => None, } } fn case2(r: Result<u8, i32>) -> Result<u8, i32> { match r { Ok(u) => Ok(u), Err(i) => Err(i), } } fn case3(r: Result<u8, i32>) -> Result<u8, i32> { let u = r?; Ok(u) } ``` Without MIR inlining, this still does not completely optimize away the `?` operator because the `Try::into_result()`, `From::from()` and `Try::from_error()` calls still exist. This does move us a bit closer to that goal though because: - We can now run the pass on mir-opt-level=1 - We no longer depend on the copy propagation pass running which is unlikely to stabilize anytime soon.
1 parent 99cb9cc commit 6de6d70

16 files changed

+1032
-73
lines changed

src/librustc_mir/transform/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,12 @@ fn run_optimization_passes<'tcx>(
317317
// 2. It creates additional possibilities for some MIR optimizations to trigger
318318
// FIXME(#70073): Why is this done here and not in `post_borrowck_cleanup`?
319319
&deaggregator::Deaggregator,
320+
&simplify_try::SimplifyArmIdentity,
321+
&simplify_try::SimplifyBranchSame,
320322
&copy_prop::CopyPropagation,
321323
&simplify_branches::SimplifyBranches::new("after-copy-prop"),
322324
&remove_noop_landing_pads::RemoveNoopLandingPads,
323325
&simplify::SimplifyCfg::new("after-remove-noop-landing-pads"),
324-
&simplify_try::SimplifyArmIdentity,
325-
&simplify_try::SimplifyBranchSame,
326326
&simplify::SimplifyCfg::new("final"),
327327
&simplify::SimplifyLocals,
328328
];

0 commit comments

Comments
 (0)