Skip to content

Commit ee32d06

Browse files
committed
[const-prop] Don't const-prop into terminators unless mir-opt-level >= 2
1 parent 7d6ad0b commit ee32d06

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/librustc_mir/transform/const_prop.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
539539
}
540540
}
541541
}
542+
543+
fn should_const_prop(&self) -> bool {
544+
self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2
545+
}
542546
}
543547

544548
fn type_size_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -632,7 +636,7 @@ impl<'b, 'a, 'tcx> MutVisitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
632636
assert!(self.places[local].is_none());
633637
self.places[local] = Some(value);
634638

635-
if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
639+
if self.should_const_prop() {
636640
self.replace_with_const(rval, value);
637641
}
638642
}
@@ -719,16 +723,20 @@ impl<'b, 'a, 'tcx> MutVisitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
719723
&msg,
720724
);
721725
} else {
722-
if let ScalarMaybeUndef::Scalar(scalar) = value_const {
723-
*cond = self.operand_from_scalar(scalar, self.tcx.types.bool);
726+
if self.should_const_prop() {
727+
if let ScalarMaybeUndef::Scalar(scalar) = value_const {
728+
*cond = self.operand_from_scalar(scalar, self.tcx.types.bool);
729+
}
724730
}
725731
}
726732
}
727733
},
728734
TerminatorKind::SwitchInt { ref mut discr, switch_ty, .. } => {
729-
if let Some(value) = self.eval_operand(&discr, source_info) {
730-
if let ScalarMaybeUndef::Scalar(scalar) = self.ecx.read_scalar(value).unwrap() {
731-
*discr = self.operand_from_scalar(scalar, switch_ty);
735+
if self.should_const_prop() {
736+
if let Some(value) = self.eval_operand(&discr, source_info) {
737+
if let Ok(ScalarMaybeUndef::Scalar(scalar)) = self.ecx.read_scalar(value) {
738+
*discr = self.operand_from_scalar(scalar, switch_ty);
739+
}
732740
}
733741
}
734742
},

0 commit comments

Comments
 (0)