about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWesley Wiser <wwiser@gmail.com>2019-05-11 12:33:10 -0400
committerWesley Wiser <wwiser@gmail.com>2019-05-19 16:47:03 -0400
commitec853ba026261bc1c8c53a99d210c02f88fde54f (patch)
treee7ae6997d9f5444b0e919af5afd15b4f3736c7b3
parent2baab0eaaa8daa0f972b580748815db970ca547d (diff)
downloadrust-ec853ba026261bc1c8c53a99d210c02f88fde54f.tar.gz
rust-ec853ba026261bc1c8c53a99d210c02f88fde54f.zip
[const-prop] Don't const-prop into terminators unless mir-opt-level >= 2
-rw-r--r--src/librustc_mir/transform/const_prop.rs29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs
index 86c7f7bbded..8f3dd72c4f2 100644
--- a/src/librustc_mir/transform/const_prop.rs
+++ b/src/librustc_mir/transform/const_prop.rs
@@ -546,6 +546,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
             }
         }
     }
+
+    fn should_const_prop(&self) -> bool {
+        self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2
+    }
 }
 
 fn type_size_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -639,7 +643,7 @@ impl<'b, 'a, 'tcx> MutVisitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
                             assert!(self.places[local].is_none());
                             self.places[local] = Some(value);
 
-                            if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
+                            if self.should_const_prop() {
                                 self.replace_with_const(rval, value, statement.source_info.span);
                             }
                         }
@@ -726,20 +730,25 @@ impl<'b, 'a, 'tcx> MutVisitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
                             &msg,
                         );
                     } else {
-                        if let ScalarMaybeUndef::Scalar(scalar) = value_const {
-                            *cond = self.operand_from_scalar(
-                                scalar,
-                                self.tcx.types.bool,
-                                source_info.span,
-                            );
+                        if self.should_const_prop() {
+                            if let ScalarMaybeUndef::Scalar(scalar) = value_const {
+                                *cond = self.operand_from_scalar(
+                                    scalar,
+                                    self.tcx.types.bool,
+                                    source_info.span,
+                                );
+                            }
                         }
                     }
                 }
             },
             TerminatorKind::SwitchInt { ref mut discr, switch_ty, .. } => {
-                if let Some(value) = self.eval_operand(&discr, source_info) {
-                    if let ScalarMaybeUndef::Scalar(scalar) = self.ecx.read_scalar(value).unwrap() {
-                        *discr = self.operand_from_scalar(scalar, switch_ty, source_info.span);
+                if self.should_const_prop() {
+                    if let Some(value) = self.eval_operand(&discr, source_info) {
+                        if let ScalarMaybeUndef::Scalar(scalar) =
+                                self.ecx.read_scalar(value).unwrap() {
+                            *discr = self.operand_from_scalar(scalar, switch_ty, source_info.span);
+                        }
                     }
                 }
             },