Auto merge of #66074 - wesleywiser:test_run_const_prop, r=oli-obk

[mir-opt] Turn on the `ConstProp` pass by default

perf.rlo shows that running the `ConstProp` pass results in
across-the-board wins regardless of debug or opt complilation mode. As a
result, we're turning it on to get the compile time benefits.
This commit is contained in:
bors 2019-11-19 04:38:47 +00:00
commit d1da8023da
4 changed files with 37 additions and 24 deletions

View File

@ -648,8 +648,21 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
} }
} }
fn should_const_prop(&self) -> bool { fn should_const_prop(&mut self, op: OpTy<'tcx>) -> bool {
self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
return true;
} else if self.tcx.sess.opts.debugging_opts.mir_opt_level == 0 {
return false;
}
match *op {
interpret::Operand::Immediate(Immediate::Scalar(ScalarMaybeUndef::Scalar(s))) =>
s.is_bits(),
interpret::Operand::Immediate(Immediate::ScalarPair(ScalarMaybeUndef::Scalar(l),
ScalarMaybeUndef::Scalar(r))) =>
l.is_bits() && r.is_bits(),
_ => false
}
} }
} }
@ -749,15 +762,15 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
if self.can_const_prop[local] { if self.can_const_prop[local] {
trace!("propagated into {:?}", local); trace!("propagated into {:?}", local);
if self.should_const_prop() { if let Some(value) = self.get_const(local) {
let value = if self.should_const_prop(value) {
self.get_const(local).expect("local was dead/uninitialized"); trace!("replacing {:?} with {:?}", rval, value);
trace!("replacing {:?} with {:?}", rval, value); self.replace_with_const(
self.replace_with_const( rval,
rval, value,
value, statement.source_info,
statement.source_info, );
); }
} }
} else { } else {
trace!("can't propagate into {:?}", local); trace!("can't propagate into {:?}", local);
@ -859,7 +872,7 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
&msg, &msg,
); );
} else { } else {
if self.should_const_prop() { if self.should_const_prop(value) {
if let ScalarMaybeUndef::Scalar(scalar) = value_const { if let ScalarMaybeUndef::Scalar(scalar) = value_const {
*cond = self.operand_from_scalar( *cond = self.operand_from_scalar(
scalar, scalar,
@ -872,8 +885,8 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
} }
}, },
TerminatorKind::SwitchInt { ref mut discr, switch_ty, .. } => { TerminatorKind::SwitchInt { ref mut discr, switch_ty, .. } => {
if self.should_const_prop() { if let Some(value) = self.eval_operand(&discr, source_info) {
if let Some(value) = self.eval_operand(&discr, source_info) { if self.should_const_prop(value) {
if let ScalarMaybeUndef::Scalar(scalar) = if let ScalarMaybeUndef::Scalar(scalar) =
self.ecx.read_scalar(value).unwrap() { self.ecx.read_scalar(value).unwrap() {
*discr = self.operand_from_scalar(scalar, switch_ty, source_info.span); *discr = self.operand_from_scalar(scalar, switch_ty, source_info.span);

View File

@ -8,7 +8,7 @@
// CHECK-LABEL: define i32 @nothing // CHECK-LABEL: define i32 @nothing
// CHECK-SAME: [[NOTHING_ATTRS:#[0-9]+]] // CHECK-SAME: [[NOTHING_ATTRS:#[0-9]+]]
// NO-OPT: ret i32 %_1.0 // NO-OPT: ret i32 4
// SIZE-OPT: ret i32 4 // SIZE-OPT: ret i32 4
// SPEEC-OPT: ret i32 4 // SPEEC-OPT: ret i32 4
#[no_mangle] #[no_mangle]
@ -18,7 +18,7 @@ pub fn nothing() -> i32 {
// CHECK-LABEL: define i32 @size // CHECK-LABEL: define i32 @size
// CHECK-SAME: [[SIZE_ATTRS:#[0-9]+]] // CHECK-SAME: [[SIZE_ATTRS:#[0-9]+]]
// NO-OPT: ret i32 %_1.0 // NO-OPT: ret i32 6
// SIZE-OPT: ret i32 6 // SIZE-OPT: ret i32 6
// SPEED-OPT: ret i32 6 // SPEED-OPT: ret i32 6
#[optimize(size)] #[optimize(size)]
@ -31,7 +31,7 @@ pub fn size() -> i32 {
// NO-OPT-SAME: [[NOTHING_ATTRS]] // NO-OPT-SAME: [[NOTHING_ATTRS]]
// SPEED-OPT-SAME: [[NOTHING_ATTRS]] // SPEED-OPT-SAME: [[NOTHING_ATTRS]]
// SIZE-OPT-SAME: [[SPEED_ATTRS:#[0-9]+]] // SIZE-OPT-SAME: [[SPEED_ATTRS:#[0-9]+]]
// NO-OPT: ret i32 %_1.0 // NO-OPT: ret i32 8
// SIZE-OPT: ret i32 8 // SIZE-OPT: ret i32 8
// SPEED-OPT: ret i32 8 // SPEED-OPT: ret i32 8
#[optimize(speed)] #[optimize(speed)]

View File

@ -48,7 +48,7 @@ pub fn change_loop_condition() {
} }
#[cfg(not(cfail1))] #[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody, mir_built, optimized_mir")] #[rustc_clean(cfg="cfail2", except="HirBody, mir_built")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
pub fn change_loop_condition() { pub fn change_loop_condition() {
let mut _x = 0; let mut _x = 0;
@ -70,7 +70,7 @@ pub fn add_break() {
} }
#[cfg(not(cfail1))] #[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody, mir_built, optimized_mir, typeck_tables_of")] #[rustc_clean(cfg="cfail2", except="HirBody, mir_built, typeck_tables_of")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
pub fn add_break() { pub fn add_break() {
let mut _x = 0; let mut _x = 0;
@ -141,7 +141,7 @@ pub fn change_break_label() {
} }
#[cfg(not(cfail1))] #[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody, mir_built, optimized_mir")] #[rustc_clean(cfg="cfail2", except="HirBody, mir_built")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
pub fn change_break_label() { pub fn change_break_label() {
let mut _x = 0; let mut _x = 0;
@ -191,7 +191,7 @@ pub fn change_continue_label() {
} }
#[cfg(not(cfail1))] #[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody, mir_built, optimized_mir")] #[rustc_clean(cfg="cfail2", except="HirBody, mir_built")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
pub fn change_continue_label() { pub fn change_continue_label() {
let mut _x = 0; let mut _x = 0;
@ -216,7 +216,7 @@ pub fn change_continue_to_break() {
} }
#[cfg(not(cfail1))] #[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody, mir_built, optimized_mir")] #[rustc_clean(cfg="cfail2", except="HirBody, mir_built")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
pub fn change_continue_to_break() { pub fn change_continue_to_break() {
let mut _x = 0; let mut _x = 0;

View File

@ -48,7 +48,7 @@ pub fn change_loop_condition() {
} }
#[cfg(not(cfail1))] #[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody, mir_built, optimized_mir")] #[rustc_clean(cfg="cfail2", except="HirBody, mir_built")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
pub fn change_loop_condition() { pub fn change_loop_condition() {
let mut _x = 0; let mut _x = 0;
@ -191,7 +191,7 @@ pub fn change_continue_label() {
} }
#[cfg(not(cfail1))] #[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody, mir_built, optimized_mir")] #[rustc_clean(cfg="cfail2", except="HirBody, mir_built")]
#[rustc_clean(cfg="cfail3")] #[rustc_clean(cfg="cfail3")]
pub fn change_continue_label() { pub fn change_continue_label() {
let mut _x = 0; let mut _x = 0;