Skip to content

Commit 6e19e8f

Browse files
committed
add test that does not currently optimize
1 parent a6008fa commit 6e19e8f

File tree

4 files changed

+217
-0
lines changed

4 files changed

+217
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
- // MIR for `opt_has_later_use` before InstCombine
2+
+ // MIR for `opt_has_later_use` after InstCombine
3+
4+
fn opt_has_later_use(_1: Vec<u8>) -> u8 {
5+
debug x => _1; // in scope 0 at $DIR/eq_not.rs:12:22: 12:23
6+
let mut _0: u8; // return place in scope 0 at $DIR/eq_not.rs:12:37: 12:39
7+
let _2: (); // in scope 0 at $DIR/eq_not.rs:13:5: 13:27
8+
let mut _3: bool; // in scope 0 at $DIR/eq_not.rs:13:5: 13:27
9+
let mut _4: bool; // in scope 0 at $DIR/eq_not.rs:13:13: 13:25
10+
let mut _5: usize; // in scope 0 at $DIR/eq_not.rs:13:13: 13:20
11+
let mut _6: &std::vec::Vec<u8>; // in scope 0 at $DIR/eq_not.rs:13:13: 13:14
12+
let mut _7: !; // in scope 0 at $SRC_DIR/std/src/macros.rs:LL:COL
13+
let mut _8: &u8; // in scope 0 at $DIR/eq_not.rs:14:5: 14:9
14+
let mut _9: &std::vec::Vec<u8>; // in scope 0 at $DIR/eq_not.rs:14:5: 14:6
15+
scope 1 {
16+
debug self => _6; // in scope 1 at $SRC_DIR/alloc/src/vec.rs:LL:COL
17+
}
18+
19+
bb0: {
20+
StorageLive(_2); // scope 0 at $DIR/eq_not.rs:13:5: 13:27
21+
StorageLive(_3); // scope 0 at $DIR/eq_not.rs:13:5: 13:27
22+
StorageLive(_4); // scope 0 at $DIR/eq_not.rs:13:13: 13:25
23+
StorageLive(_5); // scope 0 at $DIR/eq_not.rs:13:13: 13:20
24+
StorageLive(_6); // scope 0 at $DIR/eq_not.rs:13:13: 13:14
25+
_6 = &_1; // scope 0 at $DIR/eq_not.rs:13:13: 13:14
26+
_5 = ((*_6).1: usize); // scope 1 at $SRC_DIR/alloc/src/vec.rs:LL:COL
27+
StorageDead(_6); // scope 0 at $DIR/eq_not.rs:13:19: 13:20
28+
_4 = Eq(move _5, const 2_usize); // scope 0 at $DIR/eq_not.rs:13:13: 13:25
29+
StorageDead(_5); // scope 0 at $DIR/eq_not.rs:13:24: 13:25
30+
_3 = Not(move _4); // scope 0 at $DIR/eq_not.rs:13:5: 13:27
31+
StorageDead(_4); // scope 0 at $DIR/eq_not.rs:13:26: 13:27
32+
switchInt(_3) -> [false: bb3, otherwise: bb4]; // scope 0 at $DIR/eq_not.rs:13:5: 13:27
33+
}
34+
35+
bb1 (cleanup): {
36+
resume; // scope 0 at $DIR/eq_not.rs:12:1: 15:2
37+
}
38+
39+
bb2 (cleanup): {
40+
drop(_1) -> bb1; // scope 0 at $DIR/eq_not.rs:15:1: 15:2
41+
}
42+
43+
bb3: {
44+
_2 = const (); // scope 0 at $DIR/eq_not.rs:13:5: 13:27
45+
StorageDead(_3); // scope 0 at $DIR/eq_not.rs:13:26: 13:27
46+
StorageDead(_2); // scope 0 at $DIR/eq_not.rs:13:26: 13:27
47+
StorageLive(_8); // scope 0 at $DIR/eq_not.rs:14:5: 14:9
48+
StorageLive(_9); // scope 0 at $DIR/eq_not.rs:14:5: 14:6
49+
_9 = &_1; // scope 0 at $DIR/eq_not.rs:14:5: 14:6
50+
_8 = <Vec<u8> as Index<usize>>::index(move _9, const 0_usize) -> [return: bb5, unwind: bb2]; // scope 0 at $DIR/eq_not.rs:14:5: 14:9
51+
// mir::Constant
52+
// + span: $DIR/eq_not.rs:14:5: 14:9
53+
// + literal: Const { ty: for<'r> fn(&'r std::vec::Vec<u8>, usize) -> &'r <std::vec::Vec<u8> as std::ops::Index<usize>>::Output {<std::vec::Vec<u8> as std::ops::Index<usize>>::index}, val: Value(Scalar(<ZST>)) }
54+
}
55+
56+
bb4: {
57+
StorageLive(_7); // scope 0 at $SRC_DIR/std/src/macros.rs:LL:COL
58+
begin_panic::<&str>(const "assertion failed: x.len() == 2") -> bb2; // scope 0 at $SRC_DIR/std/src/macros.rs:LL:COL
59+
// mir::Constant
60+
// + span: $SRC_DIR/std/src/macros.rs:LL:COL
61+
// + literal: Const { ty: fn(&str) -> ! {std::rt::begin_panic::<&str>}, val: Value(Scalar(<ZST>)) }
62+
// ty::Const
63+
// + ty: &str
64+
// + val: Value(Slice { data: Allocation { bytes: [97, 115, 115, 101, 114, 116, 105, 111, 110, 32, 102, 97, 105, 108, 101, 100, 58, 32, 120, 46, 108, 101, 110, 40, 41, 32, 61, 61, 32, 50], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1073741823], len: Size { raw: 30 } }, size: Size { raw: 30 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 30 })
65+
// mir::Constant
66+
// + span: $DIR/eq_not.rs:1:1: 1:1
67+
// + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [97, 115, 115, 101, 114, 116, 105, 111, 110, 32, 102, 97, 105, 108, 101, 100, 58, 32, 120, 46, 108, 101, 110, 40, 41, 32, 61, 61, 32, 50], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1073741823], len: Size { raw: 30 } }, size: Size { raw: 30 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 30 }) }
68+
}
69+
70+
bb5: {
71+
_0 = (*_8); // scope 0 at $DIR/eq_not.rs:14:5: 14:9
72+
StorageDead(_9); // scope 0 at $DIR/eq_not.rs:14:8: 14:9
73+
StorageDead(_8); // scope 0 at $DIR/eq_not.rs:15:1: 15:2
74+
drop(_1) -> [return: bb6, unwind: bb1]; // scope 0 at $DIR/eq_not.rs:15:1: 15:2
75+
}
76+
77+
bb6: {
78+
return; // scope 0 at $DIR/eq_not.rs:15:2: 15:2
79+
}
80+
}
81+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
- // MIR for `opt_has_storage` before InstCombine
2+
+ // MIR for `opt_has_storage` after InstCombine
3+
4+
fn opt_has_storage(_1: Vec<u8>) -> () {
5+
debug x => _1; // in scope 0 at $DIR/eq_not.rs:7:20: 7:21
6+
let mut _0: (); // return place in scope 0 at $DIR/eq_not.rs:7:32: 7:32
7+
let _2: (); // in scope 0 at $DIR/eq_not.rs:8:5: 8:27
8+
let mut _3: bool; // in scope 0 at $DIR/eq_not.rs:8:5: 8:27
9+
let mut _4: bool; // in scope 0 at $DIR/eq_not.rs:8:13: 8:25
10+
let mut _5: usize; // in scope 0 at $DIR/eq_not.rs:8:13: 8:20
11+
let mut _6: &std::vec::Vec<u8>; // in scope 0 at $DIR/eq_not.rs:8:13: 8:14
12+
let mut _7: !; // in scope 0 at $SRC_DIR/std/src/macros.rs:LL:COL
13+
scope 1 {
14+
debug self => _6; // in scope 1 at $SRC_DIR/alloc/src/vec.rs:LL:COL
15+
}
16+
17+
bb0: {
18+
StorageLive(_2); // scope 0 at $DIR/eq_not.rs:8:5: 8:27
19+
StorageLive(_3); // scope 0 at $DIR/eq_not.rs:8:5: 8:27
20+
StorageLive(_4); // scope 0 at $DIR/eq_not.rs:8:13: 8:25
21+
StorageLive(_5); // scope 0 at $DIR/eq_not.rs:8:13: 8:20
22+
StorageLive(_6); // scope 0 at $DIR/eq_not.rs:8:13: 8:14
23+
_6 = &_1; // scope 0 at $DIR/eq_not.rs:8:13: 8:14
24+
_5 = ((*_6).1: usize); // scope 1 at $SRC_DIR/alloc/src/vec.rs:LL:COL
25+
StorageDead(_6); // scope 0 at $DIR/eq_not.rs:8:19: 8:20
26+
_4 = Eq(move _5, const 2_usize); // scope 0 at $DIR/eq_not.rs:8:13: 8:25
27+
StorageDead(_5); // scope 0 at $DIR/eq_not.rs:8:24: 8:25
28+
_3 = Not(move _4); // scope 0 at $DIR/eq_not.rs:8:5: 8:27
29+
StorageDead(_4); // scope 0 at $DIR/eq_not.rs:8:26: 8:27
30+
switchInt(_3) -> [false: bb3, otherwise: bb4]; // scope 0 at $DIR/eq_not.rs:8:5: 8:27
31+
}
32+
33+
bb1 (cleanup): {
34+
resume; // scope 0 at $DIR/eq_not.rs:7:1: 9:2
35+
}
36+
37+
bb2 (cleanup): {
38+
drop(_1) -> bb1; // scope 0 at $DIR/eq_not.rs:9:1: 9:2
39+
}
40+
41+
bb3: {
42+
_2 = const (); // scope 0 at $DIR/eq_not.rs:8:5: 8:27
43+
StorageDead(_3); // scope 0 at $DIR/eq_not.rs:8:26: 8:27
44+
StorageDead(_2); // scope 0 at $DIR/eq_not.rs:8:26: 8:27
45+
_0 = const (); // scope 0 at $DIR/eq_not.rs:7:32: 9:2
46+
drop(_1) -> [return: bb5, unwind: bb1]; // scope 0 at $DIR/eq_not.rs:9:1: 9:2
47+
}
48+
49+
bb4: {
50+
StorageLive(_7); // scope 0 at $SRC_DIR/std/src/macros.rs:LL:COL
51+
begin_panic::<&str>(const "assertion failed: x.len() == 2") -> bb2; // scope 0 at $SRC_DIR/std/src/macros.rs:LL:COL
52+
// mir::Constant
53+
// + span: $SRC_DIR/std/src/macros.rs:LL:COL
54+
// + literal: Const { ty: fn(&str) -> ! {std::rt::begin_panic::<&str>}, val: Value(Scalar(<ZST>)) }
55+
// ty::Const
56+
// + ty: &str
57+
// + val: Value(Slice { data: Allocation { bytes: [97, 115, 115, 101, 114, 116, 105, 111, 110, 32, 102, 97, 105, 108, 101, 100, 58, 32, 120, 46, 108, 101, 110, 40, 41, 32, 61, 61, 32, 50], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1073741823], len: Size { raw: 30 } }, size: Size { raw: 30 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 30 })
58+
// mir::Constant
59+
// + span: $DIR/eq_not.rs:1:1: 1:1
60+
// + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [97, 115, 115, 101, 114, 116, 105, 111, 110, 32, 102, 97, 105, 108, 101, 100, 58, 32, 120, 46, 108, 101, 110, 40, 41, 32, 61, 61, 32, 50], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1073741823], len: Size { raw: 30 } }, size: Size { raw: 30 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 30 }) }
61+
}
62+
63+
bb5: {
64+
return; // scope 0 at $DIR/eq_not.rs:9:2: 9:2
65+
}
66+
}
67+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
- // MIR for `opt_simple` before InstCombine
2+
+ // MIR for `opt_simple` after InstCombine
3+
4+
fn opt_simple(_1: u8) -> () {
5+
debug x => _1; // in scope 0 at $DIR/eq_not.rs:2:15: 2:16
6+
let mut _0: (); // return place in scope 0 at $DIR/eq_not.rs:2:22: 2:22
7+
let _2: (); // in scope 0 at $DIR/eq_not.rs:3:5: 3:21
8+
let mut _3: bool; // in scope 0 at $DIR/eq_not.rs:3:5: 3:21
9+
let mut _4: bool; // in scope 0 at $DIR/eq_not.rs:3:13: 3:19
10+
let mut _5: u8; // in scope 0 at $DIR/eq_not.rs:3:13: 3:14
11+
let mut _6: !; // in scope 0 at $SRC_DIR/std/src/macros.rs:LL:COL
12+
13+
bb0: {
14+
StorageLive(_2); // scope 0 at $DIR/eq_not.rs:3:5: 3:21
15+
StorageLive(_3); // scope 0 at $DIR/eq_not.rs:3:5: 3:21
16+
StorageLive(_4); // scope 0 at $DIR/eq_not.rs:3:13: 3:19
17+
StorageLive(_5); // scope 0 at $DIR/eq_not.rs:3:13: 3:14
18+
_5 = _1; // scope 0 at $DIR/eq_not.rs:3:13: 3:14
19+
_4 = Eq(move _5, const 2_u8); // scope 0 at $DIR/eq_not.rs:3:13: 3:19
20+
StorageDead(_5); // scope 0 at $DIR/eq_not.rs:3:18: 3:19
21+
_3 = Not(move _4); // scope 0 at $DIR/eq_not.rs:3:5: 3:21
22+
StorageDead(_4); // scope 0 at $DIR/eq_not.rs:3:20: 3:21
23+
switchInt(_3) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/eq_not.rs:3:5: 3:21
24+
}
25+
26+
bb1: {
27+
_2 = const (); // scope 0 at $DIR/eq_not.rs:3:5: 3:21
28+
StorageDead(_3); // scope 0 at $DIR/eq_not.rs:3:20: 3:21
29+
StorageDead(_2); // scope 0 at $DIR/eq_not.rs:3:20: 3:21
30+
_0 = const (); // scope 0 at $DIR/eq_not.rs:2:22: 4:2
31+
return; // scope 0 at $DIR/eq_not.rs:4:2: 4:2
32+
}
33+
34+
bb2: {
35+
StorageLive(_6); // scope 0 at $SRC_DIR/std/src/macros.rs:LL:COL
36+
begin_panic::<&str>(const "assertion failed: x == 2"); // scope 0 at $SRC_DIR/std/src/macros.rs:LL:COL
37+
// mir::Constant
38+
// + span: $SRC_DIR/std/src/macros.rs:LL:COL
39+
// + literal: Const { ty: fn(&str) -> ! {std::rt::begin_panic::<&str>}, val: Value(Scalar(<ZST>)) }
40+
// ty::Const
41+
// + ty: &str
42+
// + val: Value(Slice { data: Allocation { bytes: [97, 115, 115, 101, 114, 116, 105, 111, 110, 32, 102, 97, 105, 108, 101, 100, 58, 32, 120, 32, 61, 61, 32, 50], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [16777215], len: Size { raw: 24 } }, size: Size { raw: 24 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 24 })
43+
// mir::Constant
44+
// + span: $DIR/eq_not.rs:1:1: 1:1
45+
// + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [97, 115, 115, 101, 114, 116, 105, 111, 110, 32, 102, 97, 105, 108, 101, 100, 58, 32, 120, 32, 61, 61, 32, 50], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [16777215], len: Size { raw: 24 } }, size: Size { raw: 24 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 24 }) }
46+
}
47+
}
48+

src/test/mir-opt/eq_not.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// EMIT_MIR eq_not.opt_simple.InstCombine.diff
2+
fn opt_simple(x: u8) {
3+
assert!(x == 2);
4+
}
5+
6+
// EMIT_MIR eq_not.opt_has_storage.InstCombine.diff
7+
fn opt_has_storage(x: Vec<u8>) {
8+
assert!(x.len() == 2);
9+
}
10+
11+
// EMIT_MIR eq_not.opt_has_later_use.InstCombine.diff
12+
fn opt_has_later_use(x: Vec<u8>) -> u8 {
13+
assert!(x.len() == 2);
14+
x[0]
15+
}
16+
17+
fn main() {
18+
opt_simple(0);
19+
opt_has_storage(vec![]);
20+
opt_has_later_use(vec![]);
21+
}

0 commit comments

Comments
 (0)