Skip to content

Commit 253b727

Browse files
committed
Auto merge of #110713 - cjgillot:track-mir-opt, r=scottmcm
Add mir-opt tests to track MIR quality. cc `@scottmcm` `@saethlin` If you have other ideas, please say so.
2 parents b72460f + 332b7f5 commit 253b727

File tree

34 files changed

+757
-170
lines changed

34 files changed

+757
-170
lines changed

tests/mir-opt/instcombine_duplicate_switch_targets_e2e.ub_if_b.PreCodegen.after.mir

-27
This file was deleted.

tests/mir-opt/lower_intrinsics_e2e.f_u64.PreCodegen.after.mir

-22
This file was deleted.

tests/mir-opt/lower_intrinsics_e2e.f_unit.PreCodegen.after.mir

-22
This file was deleted.

tests/mir-opt/pre-codegen/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The goal of this directory is to track the quality of MIR that is given to codegen in a standard `-O` condiguration.
2+
3+
As such, feel free to `--bless` whatever changes you get here, so long as doing so doesn't add substantially more MIR.

tests/mir-opt/instcombine_duplicate_switch_targets_e2e.rs renamed to tests/mir-opt/pre-codegen/duplicate_switch_targets.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
// compile-flags: -Zmir-opt-level=2 -Zinline-mir
1+
// compile-flags: -O -Zmir-opt-level=2 -Cdebuginfo=0
22
// ignore-debug: standard library debug assertions add a panic that breaks this optimization
3+
34
#![crate_type = "lib"]
45

56
pub enum Thing {
67
A,
78
B,
89
}
910

10-
// EMIT_MIR instcombine_duplicate_switch_targets_e2e.ub_if_b.PreCodegen.after.mir
11+
// EMIT_MIR duplicate_switch_targets.ub_if_b.PreCodegen.after.mir
1112
pub unsafe fn ub_if_b(t: Thing) -> Thing {
1213
match t {
1314
Thing::A => t,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// MIR for `ub_if_b` after PreCodegen
2+
3+
fn ub_if_b(_1: Thing) -> Thing {
4+
debug t => _1; // in scope 0 at $DIR/duplicate_switch_targets.rs:+0:23: +0:24
5+
let mut _0: Thing; // return place in scope 0 at $DIR/duplicate_switch_targets.rs:+0:36: +0:41
6+
let mut _2: isize; // in scope 0 at $DIR/duplicate_switch_targets.rs:+2:9: +2:17
7+
scope 1 (inlined unreachable_unchecked) { // at $DIR/duplicate_switch_targets.rs:15:21: 15:55
8+
scope 2 {
9+
scope 3 (inlined unreachable_unchecked::runtime) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
10+
}
11+
}
12+
}
13+
14+
bb0: {
15+
_2 = discriminant(_1); // scope 0 at $DIR/duplicate_switch_targets.rs:+1:11: +1:12
16+
switchInt(move _2) -> [0: bb2, otherwise: bb1]; // scope 0 at $DIR/duplicate_switch_targets.rs:+1:5: +1:12
17+
}
18+
19+
bb1: {
20+
unreachable; // scope 2 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
21+
}
22+
23+
bb2: {
24+
_0 = move _1; // scope 0 at $DIR/duplicate_switch_targets.rs:+2:21: +2:22
25+
return; // scope 0 at $DIR/duplicate_switch_targets.rs:+5:2: +5:2
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// MIR for `f_u64` after PreCodegen
2+
3+
fn f_u64() -> () {
4+
let mut _0: (); // return place in scope 0 at $DIR/intrinsics.rs:+0:16: +0:16
5+
let mut _1: u64; // in scope 0 at $DIR/intrinsics.rs:+1:5: +1:21
6+
scope 1 (inlined f_dispatch::<u64>) { // at $DIR/intrinsics.rs:19:5: 19:21
7+
debug t => const 0_u64; // in scope 1 at $DIR/intrinsics.rs:23:22: 23:23
8+
let _2: (); // in scope 1 at $DIR/intrinsics.rs:27:9: 27:21
9+
scope 2 (inlined std::mem::size_of::<u64>) { // at $DIR/intrinsics.rs:24:8: 24:32
10+
}
11+
}
12+
13+
bb0: {
14+
StorageLive(_1); // scope 0 at $DIR/intrinsics.rs:+1:5: +1:21
15+
_1 = const 0_u64; // scope 0 at $DIR/intrinsics.rs:+1:5: +1:21
16+
_2 = f_non_zst::<u64>(move _1) -> [return: bb1, unwind unreachable]; // scope 1 at $DIR/intrinsics.rs:27:9: 27:21
17+
// mir::Constant
18+
// + span: $DIR/intrinsics.rs:27:9: 27:18
19+
// + literal: Const { ty: fn(u64) {f_non_zst::<u64>}, val: Value(<ZST>) }
20+
}
21+
22+
bb1: {
23+
StorageDead(_1); // scope 0 at $DIR/intrinsics.rs:+1:5: +1:21
24+
return; // scope 0 at $DIR/intrinsics.rs:+2:2: +2:2
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// MIR for `f_unit` after PreCodegen
2+
3+
fn f_unit() -> () {
4+
let mut _0: (); // return place in scope 0 at $DIR/intrinsics.rs:+0:17: +0:17
5+
scope 1 (inlined f_dispatch::<()>) { // at $DIR/intrinsics.rs:13:5: 13:19
6+
debug t => const (); // in scope 1 at $DIR/intrinsics.rs:23:22: 23:23
7+
let _1: (); // in scope 1 at $DIR/intrinsics.rs:25:9: 25:17
8+
scope 2 (inlined std::mem::size_of::<()>) { // at $DIR/intrinsics.rs:24:8: 24:32
9+
}
10+
}
11+
12+
bb0: {
13+
_1 = f_zst::<()>(const ()) -> [return: bb1, unwind unreachable]; // scope 1 at $DIR/intrinsics.rs:25:9: 25:17
14+
// mir::Constant
15+
// + span: $DIR/intrinsics.rs:25:9: 25:14
16+
// + literal: Const { ty: fn(()) {f_zst::<()>}, val: Value(<ZST>) }
17+
}
18+
19+
bb1: {
20+
return; // scope 0 at $DIR/intrinsics.rs:+2:2: +2:2
21+
}
22+
}

tests/mir-opt/lower_intrinsics_e2e.rs renamed to tests/mir-opt/pre-codegen/intrinsics.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
2+
// only-64bit
3+
// ignore-debug
4+
15
// Checks that we do not have any branches in the MIR for the two tested functions.
26

37
// compile-flags: -Cpanic=abort
48
#![feature(core_intrinsics)]
59
#![crate_type = "lib"]
610

7-
// EMIT_MIR lower_intrinsics_e2e.f_unit.PreCodegen.after.mir
11+
// EMIT_MIR intrinsics.f_unit.PreCodegen.after.mir
812
pub fn f_unit() {
913
f_dispatch(());
1014
}
1115

1216

13-
// EMIT_MIR lower_intrinsics_e2e.f_u64.PreCodegen.after.mir
17+
// EMIT_MIR intrinsics.f_u64.PreCodegen.after.mir
1418
pub fn f_u64() {
1519
f_dispatch(0u64);
1620
}

tests/mir-opt/const_prop/optimizes_into_variable.rs renamed to tests/mir-opt/pre-codegen/optimizes_into_variable.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// ignore-wasm32 compiled with panic=abort by default
2-
// unit-test
32
// compile-flags: -C overflow-checks=on
43

54
struct Point {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// MIR for `forward_loop` after PreCodegen
2+
3+
fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
4+
debug start => _1; // in scope 0 at $DIR/range_iter.rs:+0:21: +0:26
5+
debug end => _2; // in scope 0 at $DIR/range_iter.rs:+0:33: +0:36
6+
debug f => _3; // in scope 0 at $DIR/range_iter.rs:+0:43: +0:44
7+
let mut _0: (); // return place in scope 0 at $DIR/range_iter.rs:+0:60: +0:60
8+
let mut _4: std::ops::Range<u32>; // in scope 0 at $DIR/range_iter.rs:+1:14: +1:24
9+
let mut _5: std::ops::Range<u32>; // in scope 0 at $DIR/range_iter.rs:+1:14: +1:24
10+
let _6: (); // in scope 0 at $DIR/range_iter.rs:+1:14: +1:24
11+
let mut _7: std::option::Option<u32>; // in scope 0 at $DIR/range_iter.rs:+1:14: +1:24
12+
let mut _8: &mut std::ops::Range<u32>; // in scope 0 at $DIR/range_iter.rs:+1:14: +1:24
13+
let mut _9: isize; // in scope 0 at $DIR/range_iter.rs:+1:5: +3:6
14+
let mut _11: &impl Fn(u32); // in scope 0 at $DIR/range_iter.rs:+2:9: +2:10
15+
let mut _12: (u32,); // in scope 0 at $DIR/range_iter.rs:+2:9: +2:13
16+
scope 1 {
17+
debug iter => _5; // in scope 1 at $DIR/range_iter.rs:+1:14: +1:24
18+
let _10: u32; // in scope 1 at $DIR/range_iter.rs:+1:9: +1:10
19+
scope 2 {
20+
debug x => _10; // in scope 2 at $DIR/range_iter.rs:+1:9: +1:10
21+
}
22+
scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<u32>>::next) { // at $DIR/range_iter.rs:21:14: 21:24
23+
debug self => _8; // in scope 4 at $SRC_DIR/core/src/iter/range.rs:LL:COL
24+
}
25+
}
26+
scope 3 (inlined <std::ops::Range<u32> as IntoIterator>::into_iter) { // at $DIR/range_iter.rs:21:14: 21:24
27+
debug self => _4; // in scope 3 at $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
28+
}
29+
30+
bb0: {
31+
_4 = std::ops::Range::<u32> { start: _1, end: _2 }; // scope 0 at $DIR/range_iter.rs:+1:14: +1:24
32+
StorageLive(_5); // scope 0 at $DIR/range_iter.rs:+1:14: +1:24
33+
_5 = move _4; // scope 0 at $DIR/range_iter.rs:+1:14: +1:24
34+
goto -> bb1; // scope 1 at $DIR/range_iter.rs:+1:5: +3:6
35+
}
36+
37+
bb1: {
38+
StorageLive(_7); // scope 1 at $DIR/range_iter.rs:+1:14: +1:24
39+
_8 = &mut _5; // scope 1 at $DIR/range_iter.rs:+1:14: +1:24
40+
_7 = <std::ops::Range<u32> as iter::range::RangeIteratorImpl>::spec_next(_8) -> [return: bb9, unwind: bb7]; // scope 4 at $SRC_DIR/core/src/iter/range.rs:LL:COL
41+
// mir::Constant
42+
// + span: $SRC_DIR/core/src/iter/range.rs:LL:COL
43+
// + literal: Const { ty: for<'a> fn(&'a mut std::ops::Range<u32>) -> Option<<std::ops::Range<u32> as iter::range::RangeIteratorImpl>::Item> {<std::ops::Range<u32> as iter::range::RangeIteratorImpl>::spec_next}, val: Value(<ZST>) }
44+
}
45+
46+
bb2: {
47+
_10 = ((_7 as Some).0: u32); // scope 1 at $DIR/range_iter.rs:+1:9: +1:10
48+
StorageLive(_11); // scope 2 at $DIR/range_iter.rs:+2:9: +2:10
49+
_11 = &_3; // scope 2 at $DIR/range_iter.rs:+2:9: +2:10
50+
StorageLive(_12); // scope 2 at $DIR/range_iter.rs:+2:9: +2:13
51+
_12 = (_10,); // scope 2 at $DIR/range_iter.rs:+2:9: +2:13
52+
_6 = <impl Fn(u32) as Fn<(u32,)>>::call(move _11, move _12) -> [return: bb5, unwind: bb7]; // scope 2 at $DIR/range_iter.rs:+2:9: +2:13
53+
// mir::Constant
54+
// + span: $DIR/range_iter.rs:22:9: 22:10
55+
// + literal: Const { ty: for<'a> extern "rust-call" fn(&'a impl Fn(u32), (u32,)) -> <impl Fn(u32) as FnOnce<(u32,)>>::Output {<impl Fn(u32) as Fn<(u32,)>>::call}, val: Value(<ZST>) }
56+
}
57+
58+
bb3: {
59+
unreachable; // scope 1 at $DIR/range_iter.rs:+1:14: +1:24
60+
}
61+
62+
bb4: {
63+
StorageDead(_7); // scope 1 at $DIR/range_iter.rs:+3:5: +3:6
64+
StorageDead(_5); // scope 0 at $DIR/range_iter.rs:+3:5: +3:6
65+
drop(_3) -> bb6; // scope 0 at $DIR/range_iter.rs:+4:1: +4:2
66+
}
67+
68+
bb5: {
69+
StorageDead(_12); // scope 2 at $DIR/range_iter.rs:+2:12: +2:13
70+
StorageDead(_11); // scope 2 at $DIR/range_iter.rs:+2:12: +2:13
71+
StorageDead(_7); // scope 1 at $DIR/range_iter.rs:+3:5: +3:6
72+
goto -> bb1; // scope 1 at $DIR/range_iter.rs:+1:5: +3:6
73+
}
74+
75+
bb6: {
76+
return; // scope 0 at $DIR/range_iter.rs:+4:2: +4:2
77+
}
78+
79+
bb7 (cleanup): {
80+
drop(_3) -> [return: bb8, unwind terminate]; // scope 0 at $DIR/range_iter.rs:+4:1: +4:2
81+
}
82+
83+
bb8 (cleanup): {
84+
resume; // scope 0 at $DIR/range_iter.rs:+0:1: +4:2
85+
}
86+
87+
bb9: {
88+
_9 = discriminant(_7); // scope 1 at $DIR/range_iter.rs:+1:14: +1:24
89+
switchInt(move _9) -> [0: bb4, 1: bb2, otherwise: bb3]; // scope 1 at $DIR/range_iter.rs:+1:14: +1:24
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// MIR for `inclusive_loop` after PreCodegen
2+
3+
fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
4+
debug start => _1; // in scope 0 at $DIR/range_iter.rs:+0:23: +0:28
5+
debug end => _2; // in scope 0 at $DIR/range_iter.rs:+0:35: +0:38
6+
debug f => _3; // in scope 0 at $DIR/range_iter.rs:+0:45: +0:46
7+
let mut _0: (); // return place in scope 0 at $DIR/range_iter.rs:+0:62: +0:62
8+
let mut _4: std::ops::RangeInclusive<u32>; // in scope 0 at $DIR/range_iter.rs:+1:14: +1:25
9+
let mut _5: std::ops::RangeInclusive<u32>; // in scope 0 at $DIR/range_iter.rs:+1:14: +1:25
10+
let _6: (); // in scope 0 at $DIR/range_iter.rs:+1:14: +1:25
11+
let mut _7: std::option::Option<u32>; // in scope 0 at $DIR/range_iter.rs:+1:14: +1:25
12+
let mut _8: &mut std::ops::RangeInclusive<u32>; // in scope 0 at $DIR/range_iter.rs:+1:14: +1:25
13+
let mut _9: isize; // in scope 0 at $DIR/range_iter.rs:+1:5: +3:6
14+
let mut _11: &impl Fn(u32); // in scope 0 at $DIR/range_iter.rs:+2:9: +2:10
15+
let mut _12: (u32,); // in scope 0 at $DIR/range_iter.rs:+2:9: +2:13
16+
scope 1 {
17+
debug iter => _5; // in scope 1 at $DIR/range_iter.rs:+1:14: +1:25
18+
let _10: u32; // in scope 1 at $DIR/range_iter.rs:+1:9: +1:10
19+
scope 2 {
20+
debug x => _10; // in scope 2 at $DIR/range_iter.rs:+1:9: +1:10
21+
}
22+
scope 5 (inlined iter::range::<impl Iterator for RangeInclusive<u32>>::next) { // at $DIR/range_iter.rs:28:14: 28:25
23+
debug self => _8; // in scope 5 at $SRC_DIR/core/src/iter/range.rs:LL:COL
24+
}
25+
}
26+
scope 3 (inlined RangeInclusive::<u32>::new) { // at $DIR/range_iter.rs:28:14: 28:25
27+
debug start => _1; // in scope 3 at $SRC_DIR/core/src/ops/range.rs:LL:COL
28+
debug end => _2; // in scope 3 at $SRC_DIR/core/src/ops/range.rs:LL:COL
29+
}
30+
scope 4 (inlined <RangeInclusive<u32> as IntoIterator>::into_iter) { // at $DIR/range_iter.rs:28:14: 28:25
31+
debug self => _4; // in scope 4 at $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
32+
}
33+
34+
bb0: {
35+
_4 = RangeInclusive::<u32> { start: _1, end: _2, exhausted: const false }; // scope 3 at $SRC_DIR/core/src/ops/range.rs:LL:COL
36+
StorageLive(_5); // scope 0 at $DIR/range_iter.rs:+1:14: +1:25
37+
_5 = move _4; // scope 0 at $DIR/range_iter.rs:+1:14: +1:25
38+
goto -> bb1; // scope 1 at $DIR/range_iter.rs:+1:5: +3:6
39+
}
40+
41+
bb1: {
42+
StorageLive(_7); // scope 1 at $DIR/range_iter.rs:+1:14: +1:25
43+
_8 = &mut _5; // scope 1 at $DIR/range_iter.rs:+1:14: +1:25
44+
_7 = <RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next(_8) -> [return: bb9, unwind: bb7]; // scope 5 at $SRC_DIR/core/src/iter/range.rs:LL:COL
45+
// mir::Constant
46+
// + span: $SRC_DIR/core/src/iter/range.rs:LL:COL
47+
// + literal: Const { ty: for<'a> fn(&'a mut RangeInclusive<u32>) -> Option<<RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::Item> {<RangeInclusive<u32> as iter::range::RangeInclusiveIteratorImpl>::spec_next}, val: Value(<ZST>) }
48+
}
49+
50+
bb2: {
51+
_10 = ((_7 as Some).0: u32); // scope 1 at $DIR/range_iter.rs:+1:9: +1:10
52+
StorageLive(_11); // scope 2 at $DIR/range_iter.rs:+2:9: +2:10
53+
_11 = &_3; // scope 2 at $DIR/range_iter.rs:+2:9: +2:10
54+
StorageLive(_12); // scope 2 at $DIR/range_iter.rs:+2:9: +2:13
55+
_12 = (_10,); // scope 2 at $DIR/range_iter.rs:+2:9: +2:13
56+
_6 = <impl Fn(u32) as Fn<(u32,)>>::call(move _11, move _12) -> [return: bb5, unwind: bb7]; // scope 2 at $DIR/range_iter.rs:+2:9: +2:13
57+
// mir::Constant
58+
// + span: $DIR/range_iter.rs:29:9: 29:10
59+
// + literal: Const { ty: for<'a> extern "rust-call" fn(&'a impl Fn(u32), (u32,)) -> <impl Fn(u32) as FnOnce<(u32,)>>::Output {<impl Fn(u32) as Fn<(u32,)>>::call}, val: Value(<ZST>) }
60+
}
61+
62+
bb3: {
63+
unreachable; // scope 1 at $DIR/range_iter.rs:+1:14: +1:25
64+
}
65+
66+
bb4: {
67+
StorageDead(_7); // scope 1 at $DIR/range_iter.rs:+3:5: +3:6
68+
StorageDead(_5); // scope 0 at $DIR/range_iter.rs:+3:5: +3:6
69+
drop(_3) -> bb6; // scope 0 at $DIR/range_iter.rs:+4:1: +4:2
70+
}
71+
72+
bb5: {
73+
StorageDead(_12); // scope 2 at $DIR/range_iter.rs:+2:12: +2:13
74+
StorageDead(_11); // scope 2 at $DIR/range_iter.rs:+2:12: +2:13
75+
StorageDead(_7); // scope 1 at $DIR/range_iter.rs:+3:5: +3:6
76+
goto -> bb1; // scope 1 at $DIR/range_iter.rs:+1:5: +3:6
77+
}
78+
79+
bb6: {
80+
return; // scope 0 at $DIR/range_iter.rs:+4:2: +4:2
81+
}
82+
83+
bb7 (cleanup): {
84+
drop(_3) -> [return: bb8, unwind terminate]; // scope 0 at $DIR/range_iter.rs:+4:1: +4:2
85+
}
86+
87+
bb8 (cleanup): {
88+
resume; // scope 0 at $DIR/range_iter.rs:+0:1: +4:2
89+
}
90+
91+
bb9: {
92+
_9 = discriminant(_7); // scope 1 at $DIR/range_iter.rs:+1:14: +1:25
93+
switchInt(move _9) -> [0: bb4, 1: bb2, otherwise: bb3]; // scope 1 at $DIR/range_iter.rs:+1:14: +1:25
94+
}
95+
}

0 commit comments

Comments
 (0)