diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2023-06-13 18:07:55 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2023-07-20 21:30:51 +0000 |
| commit | 4a177406ee869e6e6a067b7796808eca7de7fbb2 (patch) | |
| tree | 957b69ed48bdd94e4ab52a9acdd446a4d84b560d | |
| parent | 3f708add2f128d276fd53d422e0e79cd51188632 (diff) | |
Inline should_const_prop.
| -rw-r--r-- | compiler/rustc_mir_transform/src/const_prop.rs | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index de9daf45269..7529ed8186b 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -541,7 +541,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // type whose creation requires no write. E.g. a generator whose initial state // consists solely of uninitialized memory (so it doesn't capture any locals). let value = self.get_const(place)?; - if !self.should_const_prop(&value) { + if !self.tcx.consider_optimizing(|| format!("ConstantPropagation - {value:?}")) { return None; } trace!("replacing {:?} with {:?}", place, value); @@ -551,10 +551,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { let Right(imm) = imm else { return None }; match *imm { - interpret::Immediate::Scalar(scalar) => { + Immediate::Scalar(scalar) if scalar.try_to_int().is_ok() => { Some(self.operand_from_scalar(scalar, value.layout.ty)) } - Immediate::ScalarPair(..) => { + Immediate::ScalarPair(l, r) if l.try_to_int().is_ok() && r.try_to_int().is_ok() => { let alloc = self .ecx .intern_with_temp_alloc(value.layout, |ecx, dest| { @@ -578,21 +578,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } } - /// Returns `true` if and only if this `op` should be const-propagated into. - fn should_const_prop(&mut self, op: &OpTy<'tcx>) -> bool { - if !self.tcx.consider_optimizing(|| format!("ConstantPropagation - OpTy: {:?}", op)) { - return false; - } - - match **op { - interpret::Operand::Immediate(Immediate::Scalar(s)) => s.try_to_int().is_ok(), - interpret::Operand::Immediate(Immediate::ScalarPair(l, r)) => { - l.try_to_int().is_ok() && r.try_to_int().is_ok() - } - _ => false, - } - } - fn ensure_not_propagated(&self, local: Local) { if cfg!(debug_assertions) { assert!( @@ -744,8 +729,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> { ) -> Option<PlaceElem<'tcx>> { if let PlaceElem::Index(local) = elem && let Some(value) = self.get_const(local.into()) - && self.should_const_prop(&value) - && let interpret::Operand::Immediate(interpret::Immediate::Scalar(scalar)) = *value + && let interpret::Operand::Immediate(Immediate::Scalar(scalar)) = *value && let Ok(offset) = scalar.to_target_usize(&self.tcx) && let Some(min_length) = offset.checked_add(1) { |
