Skip to content

Commit db5f6df

Browse files
wesleywiserMark-Simulacrum
authored andcommitted
[mir-opt] Disable the ConsideredEqual logic in SimplifyBranchSame opt
The logic is currently broken and we need to disable it to fix a beta regression (see rust-lang#76803)
1 parent 2e91e4d commit db5f6df

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

src/librustc_mir/transform/simplify_try.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
616616
&& bb_l.terminator().kind == bb_r.terminator().kind;
617617
let statement_check = || {
618618
bb_l.statements.iter().zip(&bb_r.statements).try_fold(StatementEquality::TrivialEqual, |acc,(l,r)| {
619-
let stmt_equality = self.statement_equality(*adt_matched_on, &l, bb_l_idx, &r, bb_r_idx);
619+
let stmt_equality = self.statement_equality(*adt_matched_on, &l, bb_l_idx, &r, bb_r_idx, self.tcx.sess.opts.debugging_opts.mir_opt_level);
620620
if matches!(stmt_equality, StatementEquality::NotEqual) {
621621
// short circuit
622622
None
@@ -676,6 +676,7 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
676676
x_bb_idx: BasicBlock,
677677
y: &Statement<'tcx>,
678678
y_bb_idx: BasicBlock,
679+
mir_opt_level: usize,
679680
) -> StatementEquality {
680681
let helper = |rhs: &Rvalue<'tcx>,
681682
place: &Box<Place<'tcx>>,
@@ -694,7 +695,13 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
694695

695696
match rhs {
696697
Rvalue::Use(operand) if operand.place() == Some(adt_matched_on) => {
697-
StatementEquality::ConsideredEqual(side_to_choose)
698+
// FIXME(76803): This logic is currently broken because it does not take into
699+
// account the current discriminant value.
700+
if mir_opt_level > 2 {
701+
StatementEquality::ConsideredEqual(side_to_choose)
702+
} else {
703+
StatementEquality::NotEqual
704+
}
698705
}
699706
_ => {
700707
trace!(

src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff

+12-15
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,24 @@
1313

1414
bb0: {
1515
_2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16
16-
- switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16
17-
+ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16
16+
switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16
1817
}
1918

2019
bb1: {
21-
- discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21
22-
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
23-
- }
24-
-
25-
- bb2: {
26-
- unreachable; // scope 0 at $DIR/simplify-arm.rs:10:11: 10:12
27-
- }
28-
-
29-
- bb3: {
20+
discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21
21+
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
22+
}
23+
24+
bb2: {
25+
unreachable; // scope 0 at $DIR/simplify-arm.rs:10:11: 10:12
26+
}
27+
28+
bb3: {
3029
_0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
31-
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
32-
+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
30+
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
3331
}
3432

35-
- bb4: {
36-
+ bb2: {
33+
bb4: {
3734
return; // scope 0 at $DIR/simplify-arm.rs:14:2: 14:2
3835
}
3936
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-pass
2+
3+
#[derive(Debug, Eq, PartialEq)]
4+
pub enum Type {
5+
A,
6+
B,
7+
}
8+
9+
10+
pub fn encode(v: Type) -> Type {
11+
match v {
12+
Type::A => Type::B,
13+
_ => v,
14+
}
15+
}
16+
17+
fn main() {
18+
assert_eq!(Type::B, encode(Type::A));
19+
}

0 commit comments

Comments
 (0)