Skip to content

Commit 15e0098

Browse files
committed
Add a more direct for not_equals optimization in InstCombine
The previous test's diff was changed by the const_goto pass such that the Ne(_1, false) pattern did not show anymore
1 parent 2803ce0 commit 15e0098

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
11
- // MIR for `opt` before InstCombine
22
+ // MIR for `opt` after InstCombine
33

4-
fn opt(_1: Option<()>) -> bool {
4+
fn opt(_1: bool) -> u32 {
55
debug x => _1; // in scope 0 at $DIR/not_equal_false.rs:3:8: 3:9
6-
let mut _0: bool; // return place in scope 0 at $DIR/not_equal_false.rs:3:26: 3:30
7-
let mut _2: isize; // in scope 0 at $DIR/not_equal_false.rs:4:17: 4:21
8-
let mut _3: isize; // in scope 0 at $DIR/not_equal_false.rs:4:38: 4:45
6+
let mut _0: u32; // return place in scope 0 at $DIR/not_equal_false.rs:3:20: 3:23
7+
let mut _2: bool; // in scope 0 at $DIR/not_equal_false.rs:4:8: 4:18
8+
let mut _3: bool; // in scope 0 at $DIR/not_equal_false.rs:4:8: 4:9
99

1010
bb0: {
11-
_2 = discriminant(_1); // scope 0 at $DIR/not_equal_false.rs:4:17: 4:21
12-
switchInt(move _2) -> [0_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/not_equal_false.rs:4:17: 4:21
11+
StorageLive(_2); // scope 0 at $DIR/not_equal_false.rs:4:8: 4:18
12+
StorageLive(_3); // scope 0 at $DIR/not_equal_false.rs:4:8: 4:9
13+
_3 = _1; // scope 0 at $DIR/not_equal_false.rs:4:8: 4:9
14+
- _2 = Ne(move _3, const false); // scope 0 at $DIR/not_equal_false.rs:4:8: 4:18
15+
+ _2 = move _3; // scope 0 at $DIR/not_equal_false.rs:4:8: 4:18
16+
StorageDead(_3); // scope 0 at $DIR/not_equal_false.rs:4:17: 4:18
17+
switchInt(_2) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/not_equal_false.rs:4:5: 4:35
1318
}
1419

1520
bb1: {
16-
_0 = const true; // scope 0 at $DIR/not_equal_false.rs:4:5: 4:46
17-
return; // scope 0 at $DIR/not_equal_false.rs:4:5: 4:46
21+
_0 = const 1_u32; // scope 0 at $DIR/not_equal_false.rs:4:32: 4:33
22+
goto -> bb3; // scope 0 at $DIR/not_equal_false.rs:4:5: 4:35
1823
}
1924

2025
bb2: {
21-
_3 = discriminant(_1); // scope 0 at $DIR/not_equal_false.rs:4:38: 4:45
22-
switchInt(move _3) -> [1_isize: bb5, otherwise: bb4]; // scope 0 at $DIR/not_equal_false.rs:4:38: 4:45
26+
_0 = const 0_u32; // scope 0 at $DIR/not_equal_false.rs:4:21: 4:22
27+
goto -> bb3; // scope 0 at $DIR/not_equal_false.rs:4:5: 4:35
2328
}
2429

2530
bb3: {
26-
goto -> bb1; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
27-
}
28-
29-
bb4: {
30-
_0 = const false; // scope 0 at $DIR/not_equal_false.rs:4:5: 4:46
31-
return; // scope 0 at $DIR/not_equal_false.rs:4:5: 4:46
32-
}
33-
34-
bb5: {
35-
goto -> bb1; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
31+
StorageDead(_2); // scope 0 at $DIR/not_equal_false.rs:5:1: 5:2
32+
return; // scope 0 at $DIR/not_equal_false.rs:5:2: 5:2
3633
}
3734
}
3835

src/test/mir-opt/not_equal_false.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// EMIT_MIR not_equal_false.opt.InstCombine.diff
22

3-
fn opt(x: Option<()>) -> bool {
4-
matches!(x, None) || matches!(x, Some(_))
3+
fn opt(x: bool) -> u32 {
4+
if x != false { 0 } else { 1 }
55
}
66

77
fn main() {
8-
opt(None);
8+
opt(false);
99
}

0 commit comments

Comments
 (0)