about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2020-10-17 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2020-10-26 10:48:28 +0100
commit4c3e06a0ba557c5915d8c00f23455461549f07f6 (patch)
treee0b64a5783458c55f6c30a60969b3268055bc5ba
parent52d37826858ee4dad6b66a3060994f41df247770 (diff)
downloadrust-4c3e06a0ba557c5915d8c00f23455461549f07f6.tar.gz
rust-4c3e06a0ba557c5915d8c00f23455461549f07f6.zip
simplify-locals: Remove unused assignments regardless of rvalue kind
-rw-r--r--compiler/rustc_mir/src/transform/simplify.rs26
-rw-r--r--src/test/codegen-units/item-collection/instantiation-through-vtable.rs3
-rw-r--r--src/test/codegen/lifetime_start_end.rs6
-rw-r--r--src/test/codegen/loads.rs2
-rw-r--r--src/test/codegen/naked-functions.rs2
-rw-r--r--src/test/codegen/refs.rs2
-rw-r--r--src/test/incremental/hashes/closure_expressions.rs4
-rw-r--r--src/test/mir-opt/simplify_locals.c.SimplifyLocals.diff12
-rw-r--r--src/test/mir-opt/simplify_locals.r.SimplifyLocals.diff16
-rw-r--r--src/test/mir-opt/simplify_locals.t1.SimplifyLocals.diff5
-rw-r--r--src/test/mir-opt/simplify_locals.t2.SimplifyLocals.diff16
-rw-r--r--src/test/mir-opt/simplify_locals.t3.SimplifyLocals.diff10
-rw-r--r--src/test/ui/recursion/issue-38591-non-regular-dropck-recursion.rs1
13 files changed, 36 insertions, 69 deletions
diff --git a/compiler/rustc_mir/src/transform/simplify.rs b/compiler/rustc_mir/src/transform/simplify.rs
index 183111877d1..b7c9a3a8688 100644
--- a/compiler/rustc_mir/src/transform/simplify.rs
+++ b/compiler/rustc_mir/src/transform/simplify.rs
@@ -439,31 +439,7 @@ impl Visitor<'_> for UsedLocals {
             StatementKind::StorageLive(_local) | StatementKind::StorageDead(_local) => {}
 
             StatementKind::Assign(box (ref place, ref rvalue)) => {
-                let can_skip = match rvalue {
-                    Rvalue::Use(_)
-                    | Rvalue::Discriminant(_)
-                    | Rvalue::BinaryOp(_, _, _)
-                    | Rvalue::CheckedBinaryOp(_, _, _)
-                    | Rvalue::Repeat(_, _)
-                    | Rvalue::AddressOf(_, _)
-                    | Rvalue::Len(_)
-                    | Rvalue::UnaryOp(_, _)
-                    | Rvalue::Aggregate(_, _) => true,
-
-                    Rvalue::Ref(..)
-                    | Rvalue::ThreadLocalRef(..)
-                    | Rvalue::Cast(..)
-                    | Rvalue::NullaryOp(..) => false,
-                };
-                if can_skip {
-                    self.visit_lhs(place, location);
-                } else {
-                    self.visit_place(
-                        place,
-                        PlaceContext::MutatingUse(MutatingUseContext::Store),
-                        location,
-                    );
-                }
+                self.visit_lhs(place, location);
                 self.visit_rvalue(rvalue, location);
             }
 
diff --git a/src/test/codegen-units/item-collection/instantiation-through-vtable.rs b/src/test/codegen-units/item-collection/instantiation-through-vtable.rs
index 63966a7ec97..ce6757a047c 100644
--- a/src/test/codegen-units/item-collection/instantiation-through-vtable.rs
+++ b/src/test/codegen-units/item-collection/instantiation-through-vtable.rs
@@ -1,6 +1,5 @@
 // ignore-tidy-linelength
-// compile-flags:-Zprint-mono-items=eager
-// compile-flags:-Zinline-in-all-cgus
+// compile-flags:-Zprint-mono-items=eager -Zinline-in-all-cgus -Zmir-opt-level=0
 
 #![deny(dead_code)]
 #![feature(start)]
diff --git a/src/test/codegen/lifetime_start_end.rs b/src/test/codegen/lifetime_start_end.rs
index 9df46bb3dd1..da35789ce8d 100644
--- a/src/test/codegen/lifetime_start_end.rs
+++ b/src/test/codegen/lifetime_start_end.rs
@@ -1,4 +1,4 @@
-// compile-flags: -O -C no-prepopulate-passes
+// compile-flags: -O -C no-prepopulate-passes -Zmir-opt-level=0
 
 #![crate_type = "lib"]
 
@@ -18,10 +18,10 @@ pub fn test() {
 // CHECK: [[S_b:%[0-9]+]] = bitcast { i32, i32 }** %b to i8*
 // CHECK: call void @llvm.lifetime.start{{.*}}(i{{[0-9 ]+}}, i8* [[S_b]])
 
-// CHECK: [[S__4:%[0-9]+]] = bitcast { i32, i32 }* %_4 to i8*
+// CHECK: [[S__4:%[0-9]+]] = bitcast { i32, i32 }* %_5 to i8*
 // CHECK: call void @llvm.lifetime.start{{.*}}(i{{[0-9 ]+}}, i8* [[S__4]])
 
-// CHECK: [[E__4:%[0-9]+]] = bitcast { i32, i32 }* %_4 to i8*
+// CHECK: [[E__4:%[0-9]+]] = bitcast { i32, i32 }* %_5 to i8*
 // CHECK: call void @llvm.lifetime.end{{.*}}(i{{[0-9 ]+}}, i8* [[E__4]])
 
 // CHECK: [[E_b:%[0-9]+]] = bitcast { i32, i32 }** %b to i8*
diff --git a/src/test/codegen/loads.rs b/src/test/codegen/loads.rs
index e164f5115ff..3c9ecec2cbf 100644
--- a/src/test/codegen/loads.rs
+++ b/src/test/codegen/loads.rs
@@ -1,4 +1,4 @@
-// compile-flags: -C no-prepopulate-passes
+// compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0
 
 #![crate_type = "lib"]
 
diff --git a/src/test/codegen/naked-functions.rs b/src/test/codegen/naked-functions.rs
index 493c1b9f0ba..5e76f1d67e6 100644
--- a/src/test/codegen/naked-functions.rs
+++ b/src/test/codegen/naked-functions.rs
@@ -1,4 +1,4 @@
-// compile-flags: -C no-prepopulate-passes
+// compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0
 
 #![crate_type = "lib"]
 #![feature(naked_functions)]
diff --git a/src/test/codegen/refs.rs b/src/test/codegen/refs.rs
index 15f99fd0c22..b4cc26f3f9d 100644
--- a/src/test/codegen/refs.rs
+++ b/src/test/codegen/refs.rs
@@ -1,4 +1,4 @@
-// compile-flags: -C no-prepopulate-passes
+// compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0
 
 #![crate_type = "lib"]
 
diff --git a/src/test/incremental/hashes/closure_expressions.rs b/src/test/incremental/hashes/closure_expressions.rs
index 7372cbc9156..4a00a6c72f7 100644
--- a/src/test/incremental/hashes/closure_expressions.rs
+++ b/src/test/incremental/hashes/closure_expressions.rs
@@ -7,7 +7,7 @@
 
 // build-pass (FIXME(62277): could be check-pass?)
 // revisions: cfail1 cfail2 cfail3
-// compile-flags: -Z query-dep-graph -Zincremental-ignore-spans
+// compile-flags: -Z query-dep-graph -Zincremental-ignore-spans -Zmir-opt-level=0
 
 #![allow(warnings)]
 #![feature(rustc_attrs)]
@@ -53,7 +53,7 @@ pub fn change_parameter_pattern() {
 }
 
 #[cfg(not(cfail1))]
-#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, typeck")]
+#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, typeck, optimized_mir")]
 #[rustc_clean(cfg="cfail3")]
 pub fn change_parameter_pattern() {
     let _ = |(x,): (u32,)| x;
diff --git a/src/test/mir-opt/simplify_locals.c.SimplifyLocals.diff b/src/test/mir-opt/simplify_locals.c.SimplifyLocals.diff
index dbf6e894697..dbac7dff9e2 100644
--- a/src/test/mir-opt/simplify_locals.c.SimplifyLocals.diff
+++ b/src/test/mir-opt/simplify_locals.c.SimplifyLocals.diff
@@ -4,8 +4,8 @@
   fn c() -> () {
       let mut _0: ();                      // return place in scope 0 at $DIR/simplify-locals.rs:13:8: 13:8
       let _1: [u8; 10];                    // in scope 0 at $DIR/simplify-locals.rs:14:9: 14:14
-      let mut _2: &[u8];                   // in scope 0 at $DIR/simplify-locals.rs:16:20: 16:26
-      let mut _3: &[u8; 10];               // in scope 0 at $DIR/simplify-locals.rs:16:20: 16:26
+-     let mut _2: &[u8];                   // in scope 0 at $DIR/simplify-locals.rs:16:20: 16:26
+-     let mut _3: &[u8; 10];               // in scope 0 at $DIR/simplify-locals.rs:16:20: 16:26
 -     let _4: &[u8; 10];                   // in scope 0 at $DIR/simplify-locals.rs:16:20: 16:26
       scope 1 {
           debug bytes => _1;               // in scope 1 at $DIR/simplify-locals.rs:14:9: 14:14
@@ -16,10 +16,10 @@
       bb0: {
           StorageLive(_1);                 // scope 0 at $DIR/simplify-locals.rs:14:9: 14:14
           _1 = [const 0_u8; 10];           // scope 0 at $DIR/simplify-locals.rs:14:17: 14:26
-          StorageLive(_2);                 // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
-          _3 = &_1;                        // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
-          _2 = move _3 as &[u8] (Pointer(Unsize)); // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
-          StorageDead(_2);                 // scope 1 at $DIR/simplify-locals.rs:16:26: 16:27
+-         StorageLive(_2);                 // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
+-         _3 = &_1;                        // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
+-         _2 = move _3 as &[u8] (Pointer(Unsize)); // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
+-         StorageDead(_2);                 // scope 1 at $DIR/simplify-locals.rs:16:26: 16:27
           _0 = const ();                   // scope 0 at $DIR/simplify-locals.rs:13:8: 17:2
           StorageDead(_1);                 // scope 0 at $DIR/simplify-locals.rs:17:1: 17:2
           return;                          // scope 0 at $DIR/simplify-locals.rs:17:2: 17:2
diff --git a/src/test/mir-opt/simplify_locals.r.SimplifyLocals.diff b/src/test/mir-opt/simplify_locals.r.SimplifyLocals.diff
index a5970585c83..85cf398d316 100644
--- a/src/test/mir-opt/simplify_locals.r.SimplifyLocals.diff
+++ b/src/test/mir-opt/simplify_locals.r.SimplifyLocals.diff
@@ -4,8 +4,8 @@
   fn r() -> () {
       let mut _0: ();                      // return place in scope 0 at $DIR/simplify-locals.rs:32:8: 32:8
       let mut _1: i32;                     // in scope 0 at $DIR/simplify-locals.rs:33:9: 33:14
-      let mut _2: &i32;                    // in scope 0 at $DIR/simplify-locals.rs:35:13: 35:15
-      let mut _3: &mut i32;                // in scope 0 at $DIR/simplify-locals.rs:36:13: 36:19
+-     let mut _2: &i32;                    // in scope 0 at $DIR/simplify-locals.rs:35:13: 35:15
+-     let mut _3: &mut i32;                // in scope 0 at $DIR/simplify-locals.rs:36:13: 36:19
       scope 1 {
           debug a => _1;                   // in scope 1 at $DIR/simplify-locals.rs:33:9: 33:14
           scope 2 {
@@ -17,12 +17,12 @@
       bb0: {
           StorageLive(_1);                 // scope 0 at $DIR/simplify-locals.rs:33:9: 33:14
           _1 = const 1_i32;                // scope 0 at $DIR/simplify-locals.rs:33:17: 33:18
-          StorageLive(_2);                 // scope 1 at $DIR/simplify-locals.rs:35:13: 35:15
-          _2 = &_1;                        // scope 1 at $DIR/simplify-locals.rs:35:13: 35:15
-          StorageDead(_2);                 // scope 1 at $DIR/simplify-locals.rs:35:15: 35:16
-          StorageLive(_3);                 // scope 2 at $DIR/simplify-locals.rs:36:13: 36:19
-          _3 = &mut _1;                    // scope 2 at $DIR/simplify-locals.rs:36:13: 36:19
-          StorageDead(_3);                 // scope 2 at $DIR/simplify-locals.rs:36:19: 36:20
+-         StorageLive(_2);                 // scope 1 at $DIR/simplify-locals.rs:35:13: 35:15
+-         _2 = &_1;                        // scope 1 at $DIR/simplify-locals.rs:35:13: 35:15
+-         StorageDead(_2);                 // scope 1 at $DIR/simplify-locals.rs:35:15: 35:16
+-         StorageLive(_3);                 // scope 2 at $DIR/simplify-locals.rs:36:13: 36:19
+-         _3 = &mut _1;                    // scope 2 at $DIR/simplify-locals.rs:36:13: 36:19
+-         StorageDead(_3);                 // scope 2 at $DIR/simplify-locals.rs:36:19: 36:20
           _0 = const ();                   // scope 0 at $DIR/simplify-locals.rs:32:8: 37:2
           StorageDead(_1);                 // scope 0 at $DIR/simplify-locals.rs:37:1: 37:2
           return;                          // scope 0 at $DIR/simplify-locals.rs:37:2: 37:2
diff --git a/src/test/mir-opt/simplify_locals.t1.SimplifyLocals.diff b/src/test/mir-opt/simplify_locals.t1.SimplifyLocals.diff
index a2dc7fd6893..991a0721cca 100644
--- a/src/test/mir-opt/simplify_locals.t1.SimplifyLocals.diff
+++ b/src/test/mir-opt/simplify_locals.t1.SimplifyLocals.diff
@@ -5,7 +5,6 @@
       let mut _0: ();                      // return place in scope 0 at $DIR/simplify-locals.rs:42:9: 42:9
 -     let _1: u32;                         // in scope 0 at $DIR/simplify-locals.rs:44:14: 44:15
 -     let mut _2: *mut u32;                // in scope 0 at $DIR/simplify-locals.rs:44:14: 44:15
-+     let mut _1: *mut u32;                // in scope 0 at $DIR/simplify-locals.rs:44:14: 44:15
       scope 1 {
       }
   
@@ -15,9 +14,7 @@
 -         _2 = &/*tls*/ mut X;             // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
 -         _1 = (*_2);                      // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
 -         StorageDead(_2);                 // scope 0 at $DIR/simplify-locals.rs:44:17: 44:18
-+         StorageLive(_1);                 // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
-+         _1 = &/*tls*/ mut X;             // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
-          StorageDead(_1);                 // scope 0 at $DIR/simplify-locals.rs:44:17: 44:18
+-         StorageDead(_1);                 // scope 0 at $DIR/simplify-locals.rs:44:17: 44:18
           _0 = const ();                   // scope 0 at $DIR/simplify-locals.rs:42:9: 45:2
           return;                          // scope 0 at $DIR/simplify-locals.rs:45:2: 45:2
       }
diff --git a/src/test/mir-opt/simplify_locals.t2.SimplifyLocals.diff b/src/test/mir-opt/simplify_locals.t2.SimplifyLocals.diff
index c119952c569..6c9ed96e78f 100644
--- a/src/test/mir-opt/simplify_locals.t2.SimplifyLocals.diff
+++ b/src/test/mir-opt/simplify_locals.t2.SimplifyLocals.diff
@@ -3,18 +3,18 @@
   
   fn t2() -> () {
       let mut _0: ();                      // return place in scope 0 at $DIR/simplify-locals.rs:48:9: 48:9
-      let _1: &mut u32;                    // in scope 0 at $DIR/simplify-locals.rs:50:14: 50:20
-      let mut _2: *mut u32;                // in scope 0 at $DIR/simplify-locals.rs:50:19: 50:20
+-     let _1: &mut u32;                    // in scope 0 at $DIR/simplify-locals.rs:50:14: 50:20
+-     let mut _2: *mut u32;                // in scope 0 at $DIR/simplify-locals.rs:50:19: 50:20
       scope 1 {
       }
   
       bb0: {
-          StorageLive(_1);                 // scope 0 at $DIR/simplify-locals.rs:50:5: 50:22
-          StorageLive(_2);                 // scope 1 at $DIR/simplify-locals.rs:50:19: 50:20
-          _2 = &/*tls*/ mut X;             // scope 1 at $DIR/simplify-locals.rs:50:19: 50:20
-          _1 = &mut (*_2);                 // scope 1 at $DIR/simplify-locals.rs:50:14: 50:20
-          StorageDead(_2);                 // scope 0 at $DIR/simplify-locals.rs:50:22: 50:23
-          StorageDead(_1);                 // scope 0 at $DIR/simplify-locals.rs:50:22: 50:23
+-         StorageLive(_1);                 // scope 0 at $DIR/simplify-locals.rs:50:5: 50:22
+-         StorageLive(_2);                 // scope 1 at $DIR/simplify-locals.rs:50:19: 50:20
+-         _2 = &/*tls*/ mut X;             // scope 1 at $DIR/simplify-locals.rs:50:19: 50:20
+-         _1 = &mut (*_2);                 // scope 1 at $DIR/simplify-locals.rs:50:14: 50:20
+-         StorageDead(_2);                 // scope 0 at $DIR/simplify-locals.rs:50:22: 50:23
+-         StorageDead(_1);                 // scope 0 at $DIR/simplify-locals.rs:50:22: 50:23
           _0 = const ();                   // scope 0 at $DIR/simplify-locals.rs:48:9: 51:2
           return;                          // scope 0 at $DIR/simplify-locals.rs:51:2: 51:2
       }
diff --git a/src/test/mir-opt/simplify_locals.t3.SimplifyLocals.diff b/src/test/mir-opt/simplify_locals.t3.SimplifyLocals.diff
index 357b3fc9d3a..2d5fb352f8b 100644
--- a/src/test/mir-opt/simplify_locals.t3.SimplifyLocals.diff
+++ b/src/test/mir-opt/simplify_locals.t3.SimplifyLocals.diff
@@ -6,8 +6,6 @@
 -     let _1: u32;                         // in scope 0 at $DIR/simplify-locals.rs:56:14: 56:21
 -     let mut _2: &mut u32;                // in scope 0 at $DIR/simplify-locals.rs:56:15: 56:21
 -     let mut _3: *mut u32;                // in scope 0 at $DIR/simplify-locals.rs:56:20: 56:21
-+     let mut _1: &mut u32;                // in scope 0 at $DIR/simplify-locals.rs:56:15: 56:21
-+     let mut _2: *mut u32;                // in scope 0 at $DIR/simplify-locals.rs:56:20: 56:21
       scope 1 {
       }
   
@@ -19,12 +17,8 @@
 -         _2 = &mut (*_3);                 // scope 1 at $DIR/simplify-locals.rs:56:15: 56:21
 -         _1 = (*_2);                      // scope 1 at $DIR/simplify-locals.rs:56:14: 56:21
 -         StorageDead(_3);                 // scope 0 at $DIR/simplify-locals.rs:56:23: 56:24
-+         StorageLive(_1);                 // scope 1 at $DIR/simplify-locals.rs:56:15: 56:21
-+         StorageLive(_2);                 // scope 1 at $DIR/simplify-locals.rs:56:20: 56:21
-+         _2 = &/*tls*/ mut X;             // scope 1 at $DIR/simplify-locals.rs:56:20: 56:21
-+         _1 = &mut (*_2);                 // scope 1 at $DIR/simplify-locals.rs:56:15: 56:21
-          StorageDead(_2);                 // scope 0 at $DIR/simplify-locals.rs:56:23: 56:24
-          StorageDead(_1);                 // scope 0 at $DIR/simplify-locals.rs:56:23: 56:24
+-         StorageDead(_2);                 // scope 0 at $DIR/simplify-locals.rs:56:23: 56:24
+-         StorageDead(_1);                 // scope 0 at $DIR/simplify-locals.rs:56:23: 56:24
           _0 = const ();                   // scope 0 at $DIR/simplify-locals.rs:54:9: 57:2
           return;                          // scope 0 at $DIR/simplify-locals.rs:57:2: 57:2
       }
diff --git a/src/test/ui/recursion/issue-38591-non-regular-dropck-recursion.rs b/src/test/ui/recursion/issue-38591-non-regular-dropck-recursion.rs
index 658def0ad5a..c857eb459b8 100644
--- a/src/test/ui/recursion/issue-38591-non-regular-dropck-recursion.rs
+++ b/src/test/ui/recursion/issue-38591-non-regular-dropck-recursion.rs
@@ -5,6 +5,7 @@
 
 // build-fail
 // normalize-stderr-test: ".nll/" -> "/"
+// compile-flags: -Zmir-opt-level=0
 
 struct S<T> {
     t: T,