Skip to content

Commit

Permalink
Bless mir_opt tests that were broken by DSE.
Browse files Browse the repository at this point in the history
Adding the DSE pass changed the emitted MIR for a bunch of other test. This commit blesses/fixes
these changes. In some cases, this required adding some `black_box` calls to inhibit the DSE
optimizations.
  • Loading branch information
JakobDegen committed Feb 18, 2022
1 parent 81f8c12 commit 7a30d3e
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 119 deletions.
177 changes: 95 additions & 82 deletions src/test/mir-opt/const_debuginfo.main.ConstDebugInfo.diff

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/test/mir-opt/const_debuginfo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// compile-flags: -C overflow-checks=no -Zunsound-mir-opts

#![feature(bench_black_box)]

struct Point {
x: u32,
y: u32,
Expand All @@ -19,6 +21,8 @@ fn main() {

let p = Point { x: 32, y: 32 };
let a = p.x + p.y;

core::hint::black_box(());
}

// EMIT_MIR const_debuginfo.main.ConstDebugInfo.diff
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ fn main() -> () {
StorageLive(_1); // scope 0 at $DIR/optimizes_into_variable.rs:12:9: 12:10
_1 = const 4_i32; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18
StorageLive(_2); // scope 1 at $DIR/optimizes_into_variable.rs:13:9: 13:10
_2 = const 3_i32; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34
StorageLive(_3); // scope 2 at $DIR/optimizes_into_variable.rs:14:9: 14:10
_3 = const 42_u32; // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:38
StorageDead(_3); // scope 2 at $DIR/optimizes_into_variable.rs:15:1: 15:2
StorageDead(_2); // scope 1 at $DIR/optimizes_into_variable.rs:15:1: 15:2
StorageDead(_1); // scope 0 at $DIR/optimizes_into_variable.rs:15:1: 15:2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ fn main() -> () {
StorageLive(_1); // scope 0 at $DIR/optimizes_into_variable.rs:12:9: 12:10
_1 = const 4_i32; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18
StorageLive(_2); // scope 1 at $DIR/optimizes_into_variable.rs:13:9: 13:10
_2 = const 3_i32; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34
StorageLive(_3); // scope 2 at $DIR/optimizes_into_variable.rs:14:9: 14:10
_3 = const 42_u32; // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:38
StorageDead(_3); // scope 2 at $DIR/optimizes_into_variable.rs:15:1: 15:2
StorageDead(_2); // scope 1 at $DIR/optimizes_into_variable.rs:15:1: 15:2
StorageDead(_1); // scope 0 at $DIR/optimizes_into_variable.rs:15:1: 15:2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
StorageLive(_5); // scope 0 at $DIR/lower_array_len.rs:7:16: 7:27
- StorageLive(_6); // scope 0 at $DIR/lower_array_len.rs:7:16: 7:27
- StorageLive(_7); // scope 0 at $DIR/lower_array_len.rs:7:16: 7:27
- _7 = _2; // scope 0 at $DIR/lower_array_len.rs:7:16: 7:27
- StorageLive(_11); // scope 0 at $DIR/lower_array_len.rs:7:16: 7:27
- _11 = _7; // scope 0 at $DIR/lower_array_len.rs:7:16: 7:27
- _6 = move _7 as &[u8] (Pointer(Unsize)); // scope 0 at $DIR/lower_array_len.rs:7:16: 7:27
- StorageDead(_7); // scope 0 at $DIR/lower_array_len.rs:7:20: 7:21
_5 = const N; // scope 0 at $DIR/lower_array_len.rs:7:16: 7:27
- StorageDead(_11); // scope 0 at $DIR/lower_array_len.rs:7:16: 7:27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
StorageLive(_5); // scope 0 at $DIR/lower_array_len.rs:18:16: 18:27
- StorageLive(_6); // scope 0 at $DIR/lower_array_len.rs:18:16: 18:27
- StorageLive(_7); // scope 0 at $DIR/lower_array_len.rs:18:16: 18:27
- _7 = &(*_2); // scope 0 at $DIR/lower_array_len.rs:18:16: 18:27
- StorageLive(_14); // scope 0 at $DIR/lower_array_len.rs:18:16: 18:27
- _14 = _7; // scope 0 at $DIR/lower_array_len.rs:18:16: 18:27
- _6 = move _7 as &[u8] (Pointer(Unsize)); // scope 0 at $DIR/lower_array_len.rs:18:16: 18:27
- StorageDead(_7); // scope 0 at $DIR/lower_array_len.rs:18:20: 18:21
_5 = const N; // scope 0 at $DIR/lower_array_len.rs:18:16: 18:27
- StorageDead(_14); // scope 0 at $DIR/lower_array_len.rs:18:16: 18:27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
bb0: {
- StorageLive(_2); // scope 0 at $DIR/lower_array_len.rs:31:5: 31:14
- StorageLive(_3); // scope 0 at $DIR/lower_array_len.rs:31:5: 31:14
- _3 = _1; // scope 0 at $DIR/lower_array_len.rs:31:5: 31:14
- StorageLive(_4); // scope 0 at $DIR/lower_array_len.rs:31:5: 31:14
- _4 = _3; // scope 0 at $DIR/lower_array_len.rs:31:5: 31:14
- _2 = move _3 as &[u8] (Pointer(Unsize)); // scope 0 at $DIR/lower_array_len.rs:31:5: 31:14
- StorageDead(_3); // scope 0 at $DIR/lower_array_len.rs:31:7: 31:8
_0 = const N; // scope 0 at $DIR/lower_array_len.rs:31:5: 31:14
- StorageDead(_4); // scope 0 at $DIR/lower_array_len.rs:31:5: 31:14
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
bb0: {
- StorageLive(_2); // scope 0 at $DIR/lower_array_len.rs:38:5: 38:14
- StorageLive(_3); // scope 0 at $DIR/lower_array_len.rs:38:5: 38:14
- _3 = &_1; // scope 0 at $DIR/lower_array_len.rs:38:5: 38:14
- StorageLive(_4); // scope 0 at $DIR/lower_array_len.rs:38:5: 38:14
- _4 = _3; // scope 0 at $DIR/lower_array_len.rs:38:5: 38:14
- _2 = move _3 as &[u8] (Pointer(Unsize)); // scope 0 at $DIR/lower_array_len.rs:38:5: 38:14
- StorageDead(_3); // scope 0 at $DIR/lower_array_len.rs:38:7: 38:8
_0 = const N; // scope 0 at $DIR/lower_array_len.rs:38:5: 38:14
- StorageDead(_4); // scope 0 at $DIR/lower_array_len.rs:38:5: 38:14
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ fn too_complex(_1: Result<i32, usize>) -> Option<i32> {
StorageDead(_7); // scope 2 at $DIR/separate_const_switch.rs:17:43: 17:44
StorageDead(_6); // scope 0 at $DIR/separate_const_switch.rs:17:43: 17:44
StorageLive(_10); // scope 0 at $DIR/separate_const_switch.rs:21:28: 21:29
_10 = ((_2 as Break).0: usize); // scope 0 at $DIR/separate_const_switch.rs:21:28: 21:29
discriminant(_0) = 0; // scope 4 at $DIR/separate_const_switch.rs:21:34: 21:38
StorageDead(_10); // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38
goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
- StorageLive(_10); // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:30
- StorageLive(_11); // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:28
- (_11.0: u8) = const 40_u8; // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:28
- _10 = const 40_u8; // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:30
- _9 = const 42_u8; // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:34
- StorageDead(_10); // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:33: 16:34
- _8 = use_u8(const 42_u8) -> bb2; // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:5: 16:35
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
}

bb0: {
- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12
- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12
- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12
_0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:20: 6:27
Expand Down
2 changes: 2 additions & 0 deletions src/test/mir-opt/tls-access.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(thread_local)]
#![feature(bench_black_box)]

#[thread_local]
static mut FOO: u8 = 3;
Expand All @@ -7,6 +8,7 @@ fn main() {
unsafe {
let a = &FOO;
FOO = 42;
core::hint::black_box(());
}
}

Expand Down
51 changes: 35 additions & 16 deletions src/test/mir-opt/tls_access.main.SimplifyCfg-final.after.mir
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
// MIR for `main` after SimplifyCfg-final

fn main() -> () {
let mut _0: (); // return place in scope 0 at $DIR/tls-access.rs:6:11: 6:11
let _2: *mut u8; // in scope 0 at $DIR/tls-access.rs:8:18: 8:21
let mut _3: *mut u8; // in scope 0 at $DIR/tls-access.rs:9:9: 9:12
let mut _0: (); // return place in scope 0 at $DIR/tls-access.rs:7:11: 7:11
let _2: *mut u8; // in scope 0 at $DIR/tls-access.rs:9:18: 9:21
let mut _3: *mut u8; // in scope 0 at $DIR/tls-access.rs:10:9: 10:12
let _4: (); // in scope 0 at $DIR/tls-access.rs:11:9: 11:34
let mut _5: (); // in scope 0 at $DIR/tls-access.rs:11:31: 11:33
scope 1 {
let _1: &u8; // in scope 1 at $DIR/tls-access.rs:8:13: 8:14
let _1: &u8; // in scope 1 at $DIR/tls-access.rs:9:13: 9:14
scope 2 {
debug a => _1; // in scope 2 at $DIR/tls-access.rs:8:13: 8:14
debug a => _1; // in scope 2 at $DIR/tls-access.rs:9:13: 9:14
scope 3 (inlined std::hint::black_box::<()>) { // at $DIR/tls-access.rs:11:9: 11:34
debug dummy => _5; // in scope 3 at $DIR/tls-access.rs:11:9: 11:34
let mut _6: (); // in scope 3 at $DIR/tls-access.rs:11:9: 11:34
}
}
}

bb0: {
StorageLive(_1); // scope 1 at $DIR/tls-access.rs:8:13: 8:14
StorageLive(_2); // scope 1 at $DIR/tls-access.rs:8:18: 8:21
_2 = &/*tls*/ mut FOO; // scope 1 at $DIR/tls-access.rs:8:18: 8:21
_1 = &(*_2); // scope 1 at $DIR/tls-access.rs:8:17: 8:21
StorageLive(_3); // scope 2 at $DIR/tls-access.rs:9:9: 9:12
_3 = &/*tls*/ mut FOO; // scope 2 at $DIR/tls-access.rs:9:9: 9:12
(*_3) = const 42_u8; // scope 2 at $DIR/tls-access.rs:9:9: 9:17
StorageDead(_3); // scope 2 at $DIR/tls-access.rs:9:17: 9:18
StorageDead(_2); // scope 1 at $DIR/tls-access.rs:10:5: 10:6
StorageDead(_1); // scope 1 at $DIR/tls-access.rs:10:5: 10:6
return; // scope 0 at $DIR/tls-access.rs:11:2: 11:2
StorageLive(_1); // scope 1 at $DIR/tls-access.rs:9:13: 9:14
StorageLive(_2); // scope 1 at $DIR/tls-access.rs:9:18: 9:21
_2 = &/*tls*/ mut FOO; // scope 1 at $DIR/tls-access.rs:9:18: 9:21
_1 = &(*_2); // scope 1 at $DIR/tls-access.rs:9:17: 9:21
StorageLive(_3); // scope 2 at $DIR/tls-access.rs:10:9: 10:12
_3 = &/*tls*/ mut FOO; // scope 2 at $DIR/tls-access.rs:10:9: 10:12
(*_3) = const 42_u8; // scope 2 at $DIR/tls-access.rs:10:9: 10:17
StorageDead(_3); // scope 2 at $DIR/tls-access.rs:10:17: 10:18
StorageLive(_4); // scope 2 at $DIR/tls-access.rs:11:9: 11:34
StorageLive(_5); // scope 2 at $DIR/tls-access.rs:11:31: 11:33
StorageLive(_6); // scope 3 at $DIR/tls-access.rs:11:9: 11:34
_4 = std::intrinsics::black_box::<()>(const ()) -> bb1; // scope 3 at $DIR/tls-access.rs:11:9: 11:34
// mir::Constant
// + span: $DIR/tls-access.rs:11:9: 11:34
// + literal: Const { ty: extern "rust-intrinsic" fn(()) {std::intrinsics::black_box::<()>}, val: Value(Scalar(<ZST>)) }
}

bb1: {
StorageDead(_6); // scope 3 at $DIR/tls-access.rs:11:9: 11:34
StorageDead(_5); // scope 2 at $DIR/tls-access.rs:11:33: 11:34
StorageDead(_4); // scope 2 at $DIR/tls-access.rs:11:34: 11:35
StorageDead(_2); // scope 1 at $DIR/tls-access.rs:12:5: 12:6
StorageDead(_1); // scope 1 at $DIR/tls-access.rs:12:5: 12:6
return; // scope 0 at $DIR/tls-access.rs:13:2: 13:2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn process_never(_1: *const !) -> () {

bb0: {
StorageLive(_2); // scope 0 at $DIR/uninhabited-enum.rs:8:8: 8:14
_2 = &(*_1); // scope 2 at $DIR/uninhabited-enum.rs:8:26: 8:33
StorageDead(_2); // scope 0 at $DIR/uninhabited-enum.rs:9:1: 9:2
unreachable; // scope 0 at $DIR/uninhabited-enum.rs:7:39: 9:2
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn process_void(_1: *const Void) -> () {

bb0: {
StorageLive(_2); // scope 0 at $DIR/uninhabited-enum.rs:14:8: 14:14
_2 = &(*_1); // scope 2 at $DIR/uninhabited-enum.rs:14:26: 14:33
StorageDead(_2); // scope 0 at $DIR/uninhabited-enum.rs:17:1: 17:2
return; // scope 0 at $DIR/uninhabited-enum.rs:17:2: 17:2
}
Expand Down

0 comments on commit 7a30d3e

Please sign in to comment.