Skip to content

Commit 2c69266

Browse files
committed
Auto merge of #76837 - wesleywiser:disable_consideredequal, r=oli-obk
[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 #76803) r? `@oli-obk`
2 parents 953f33c + dbd7226 commit 2c69266

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

compiler/rustc_mir/src/transform/simplify_try.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
612612
&& bb_l.terminator().kind == bb_r.terminator().kind;
613613
let statement_check = || {
614614
bb_l.statements.iter().zip(&bb_r.statements).try_fold(StatementEquality::TrivialEqual, |acc,(l,r)| {
615-
let stmt_equality = self.statement_equality(*adt_matched_on, &l, bb_l_idx, &r, bb_r_idx);
615+
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);
616616
if matches!(stmt_equality, StatementEquality::NotEqual) {
617617
// short circuit
618618
None
@@ -672,6 +672,7 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
672672
x_bb_idx: BasicBlock,
673673
y: &Statement<'tcx>,
674674
y_bb_idx: BasicBlock,
675+
mir_opt_level: usize,
675676
) -> StatementEquality {
676677
let helper = |rhs: &Rvalue<'tcx>,
677678
place: &Place<'tcx>,
@@ -690,7 +691,13 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
690691

691692
match rhs {
692693
Rvalue::Use(operand) if operand.place() == Some(adt_matched_on) => {
693-
StatementEquality::ConsideredEqual(side_to_choose)
694+
// FIXME(76803): This logic is currently broken because it does not take into
695+
// account the current discriminant value.
696+
if mir_opt_level > 2 {
697+
StatementEquality::ConsideredEqual(side_to_choose)
698+
} else {
699+
StatementEquality::NotEqual
700+
}
694701
}
695702
_ => {
696703
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)