move fuel checks to later points in instcombine and const_prop, add opt level flag to test
This commit is contained in:
parent
b4c9424147
commit
51c2218d1f
@ -89,10 +89,6 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
|
||||
return;
|
||||
}
|
||||
|
||||
if !tcx.consider_optimizing(|| format!("ConstantPropagation {:?} {:?}", def_id, hir_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if it's even possible to satisfy the 'where' clauses
|
||||
// for this item.
|
||||
// This branch will never be taken for any normal function.
|
||||
@ -804,7 +800,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
trace!("attepting to replace {:?} with {:?}", rval, value);
|
||||
trace!("attempting to replace {:?} with {:?}", rval, value);
|
||||
if let Err(e) = self.ecx.const_validate_operand(
|
||||
value,
|
||||
vec![],
|
||||
@ -894,6 +890,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||
return false;
|
||||
}
|
||||
|
||||
if !self.tcx.consider_optimizing(|| format!("ConstantPropagation - OpTy: {:?}", op)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
match *op {
|
||||
interpret::Operand::Immediate(Immediate::Scalar(ScalarMaybeUninit::Scalar(s))) => {
|
||||
s.is_bits()
|
||||
|
@ -20,13 +20,6 @@ pub struct InstCombine;
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for InstCombine {
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
// Check for fuel here before gathering the optimization list. If we're out of fuel,
|
||||
// we don't want to take the time to pass over the MIR only to find optimizations
|
||||
// we won't run.
|
||||
if !tcx.consider_optimizing(|| format!("InstCombine {:?} ", body.source.def_id())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// First, find optimization opportunities. This is done in a pre-pass to keep the MIR
|
||||
// read-only so that we can do global analyses on the MIR in the process (e.g.
|
||||
// `Place::ty()`).
|
||||
@ -46,13 +39,21 @@ pub struct InstCombineVisitor<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> InstCombineVisitor<'tcx> {
|
||||
fn should_combine(&self, rvalue: &Rvalue<'tcx>, location: Location) -> bool {
|
||||
self.tcx.consider_optimizing(|| {
|
||||
format!("InstCombine - Rvalue: {:?} Location: {:?}", rvalue, location)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
|
||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
||||
fn visit_rvalue(&mut self, rvalue: &mut Rvalue<'tcx>, location: Location) {
|
||||
if self.optimizations.and_stars.remove(&location) {
|
||||
if self.optimizations.and_stars.remove(&location) && self.should_combine(rvalue, location) {
|
||||
debug!("replacing `&*`: {:?}", rvalue);
|
||||
let new_place = match rvalue {
|
||||
Rvalue::Ref(_, _, place) => {
|
||||
@ -74,18 +75,24 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
|
||||
}
|
||||
|
||||
if let Some(constant) = self.optimizations.arrays_lengths.remove(&location) {
|
||||
debug!("replacing `Len([_; N])`: {:?}", rvalue);
|
||||
*rvalue = Rvalue::Use(Operand::Constant(box constant));
|
||||
if self.should_combine(rvalue, location) {
|
||||
debug!("replacing `Len([_; N])`: {:?}", rvalue);
|
||||
*rvalue = Rvalue::Use(Operand::Constant(box constant));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(operand) = self.optimizations.unneeded_equality_comparison.remove(&location) {
|
||||
debug!("replacing {:?} with {:?}", rvalue, operand);
|
||||
*rvalue = Rvalue::Use(operand);
|
||||
if self.should_combine(rvalue, location) {
|
||||
debug!("replacing {:?} with {:?}", rvalue, operand);
|
||||
*rvalue = Rvalue::Use(operand);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(place) = self.optimizations.unneeded_deref.remove(&location) {
|
||||
debug!("unneeded_deref: replacing {:?} with {:?}", rvalue, place);
|
||||
*rvalue = Rvalue::Use(Operand::Copy(place));
|
||||
if self.should_combine(rvalue, location) {
|
||||
debug!("unneeded_deref: replacing {:?} with {:?}", rvalue, place);
|
||||
*rvalue = Rvalue::Use(Operand::Copy(place));
|
||||
}
|
||||
}
|
||||
|
||||
self.super_rvalue(rvalue, location)
|
||||
|
@ -2,7 +2,7 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
// (#55495: The --error-format is to sidestep an issue in our test harness)
|
||||
// compile-flags: --error-format human -Z print-fuel=foo
|
||||
// compile-flags: -C opt-level=0 --error-format human -Z print-fuel=foo
|
||||
// build-pass (FIXME(62277): could be check-pass?)
|
||||
|
||||
struct S1(u8, u16, u8);
|
||||
|
@ -1 +1 @@
|
||||
Fuel used by foo: 7
|
||||
Fuel used by foo: 6
|
||||
|
Loading…
Reference in New Issue
Block a user