Auto merge of #112001 - saethlin:enable-matchbranchsimplification, r=cjgillot
Enable MatchBranchSimplification
This pass is one of the small number of benefits from `-Zmir-opt-level=3` that has motivated rustc_codegen_cranelift to use it:
19ed0aade6/compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs (L244-L246)
Cranelift's motivation for this is _runtime_ performance improvements in debug builds. Lifting this pass all the way to `-Zmir-opt-level=1` seems to come without significant perf overhead, so that's what I'm suggesting here.
This commit is contained in:
commit
f59d577838
@ -41,7 +41,7 @@
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
|
||||
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
|
||||
sess.mir_opt_level() >= 3
|
||||
sess.mir_opt_level() >= 1
|
||||
}
|
||||
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
@ -62,7 +62,12 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
..
|
||||
} if targets.iter().len() == 1 => {
|
||||
let (value, target) = targets.iter().next().unwrap();
|
||||
if target == targets.otherwise() {
|
||||
// We require that this block and the two possible target blocks all be
|
||||
// distinct.
|
||||
if target == targets.otherwise()
|
||||
|| bb_idx == target
|
||||
|| bb_idx == targets.otherwise()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
(discr, value, target, targets.otherwise())
|
||||
|
@ -116,6 +116,7 @@ fn select(&mut self, selcx: SelectionContext<'a, 'tcx>) -> Vec<FulfillmentError<
|
||||
}
|
||||
|
||||
impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
|
||||
#[inline]
|
||||
fn register_predicate_obligation(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
|
@ -8,8 +8,6 @@
|
||||
let mut _3: std::option::Option<T>; // in scope 0 at $DIR/simplify_locals_fixedpoint.rs:+1:51: +1:68
|
||||
let mut _4: isize; // in scope 0 at $DIR/simplify_locals_fixedpoint.rs:+1:22: +1:26
|
||||
let mut _5: isize; // in scope 0 at $DIR/simplify_locals_fixedpoint.rs:+1:13: +1:20
|
||||
- let mut _7: bool; // in scope 0 at $DIR/simplify_locals_fixedpoint.rs:+2:12: +2:20
|
||||
- let mut _8: u8; // in scope 0 at $DIR/simplify_locals_fixedpoint.rs:+2:12: +2:13
|
||||
scope 1 {
|
||||
debug a => _6; // in scope 1 at $DIR/simplify_locals_fixedpoint.rs:+1:18: +1:19
|
||||
let _6: u8; // in scope 1 at $DIR/simplify_locals_fixedpoint.rs:+1:18: +1:19
|
||||
@ -34,10 +32,9 @@
|
||||
}
|
||||
|
||||
bb2: {
|
||||
StorageLive(_6); // scope 1 at $DIR/simplify_locals_fixedpoint.rs:+1:18: +1:19
|
||||
_6 = (((_1.0: std::option::Option<u8>) as Some).0: u8); // scope 1 at $DIR/simplify_locals_fixedpoint.rs:+1:18: +1:19
|
||||
- StorageLive(_7); // scope 1 at $DIR/simplify_locals_fixedpoint.rs:+2:12: +2:20
|
||||
- _7 = Gt(_6, const 42_u8); // scope 1 at $DIR/simplify_locals_fixedpoint.rs:+2:12: +2:20
|
||||
- StorageDead(_7); // scope 1 at $DIR/simplify_locals_fixedpoint.rs:+4:9: +4:10
|
||||
StorageDead(_6); // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+5:5: +5:6
|
||||
goto -> bb3; // scope 0 at $DIR/simplify_locals_fixedpoint.rs:+1:5: +5:6
|
||||
}
|
||||
|
||||
|
21
tests/mir-opt/switch_to_self.rs
Normal file
21
tests/mir-opt/switch_to_self.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// Test that MatchBranchSimplification doesn't ICE on a SwitchInt where
|
||||
// one of the targets is the block that the SwitchInt terminates.
|
||||
#![crate_type = "lib"]
|
||||
#![feature(core_intrinsics, custom_mir)]
|
||||
use std::intrinsics::mir::*;
|
||||
|
||||
// EMIT_MIR switch_to_self.test.MatchBranchSimplification.diff
|
||||
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
|
||||
pub fn test(x: bool) {
|
||||
mir!(
|
||||
{
|
||||
Goto(bb0)
|
||||
}
|
||||
bb0 = {
|
||||
match x { false => bb0, _ => bb1 }
|
||||
}
|
||||
bb1 = {
|
||||
match x { false => bb0, _ => bb1 }
|
||||
}
|
||||
)
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
- // MIR for `test` before MatchBranchSimplification
|
||||
+ // MIR for `test` after MatchBranchSimplification
|
||||
|
||||
fn test(_1: bool) -> () {
|
||||
let mut _0: (); // return place in scope 0 at $DIR/switch_to_self.rs:+0:22: +0:22
|
||||
|
||||
bb0: {
|
||||
goto -> bb1; // scope 0 at $DIR/switch_to_self.rs:+3:13: +3:22
|
||||
}
|
||||
|
||||
bb1: {
|
||||
switchInt(_1) -> [0: bb1, otherwise: bb2]; // scope 0 at $DIR/switch_to_self.rs:+6:13: +6:47
|
||||
}
|
||||
|
||||
bb2: {
|
||||
switchInt(_1) -> [0: bb1, otherwise: bb2]; // scope 0 at $DIR/switch_to_self.rs:+9:13: +9:47
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user