@@ -52,11 +52,8 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
52
52
if let Some ( f_c) = f_c. literal . try_eval_bool ( tcx, param_env) {
53
53
// This should also be a bool because it's writing to the same place
54
54
let s_c = s_c. literal . try_eval_bool ( tcx, param_env) . unwrap ( ) ;
55
- // Check that only const assignments of opposite bool values are
56
- // permitted.
57
- if f_c != s_c {
58
- continue
59
- }
55
+ assert_ne ! ( f_c, s_c, "Unexpected match would've compared eq earlier" ) ;
56
+ continue ;
60
57
}
61
58
continue ' outer;
62
59
}
@@ -70,14 +67,19 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
70
67
bbs[ bb_idx] . terminator_mut ( ) . kind = TerminatorKind :: Goto { target : first } ;
71
68
for s in bbs[ first] . statements . iter_mut ( ) {
72
69
if let StatementKind :: Assign ( box ( _, ref mut rhs) ) = s. kind {
73
- let size = tcx. layout_of ( param_env. and ( switch_ty) ) . unwrap ( ) . size ;
74
- let const_cmp = Operand :: const_from_scalar (
75
- tcx,
76
- switch_ty,
77
- crate :: interpret:: Scalar :: from_uint ( val, size) ,
78
- rustc_span:: DUMMY_SP ,
79
- ) ;
80
- * rhs = Rvalue :: BinaryOp ( BinOp :: Eq , Operand :: Move ( discr) , const_cmp) ;
70
+ if let Rvalue :: Use ( Operand :: Constant ( c) ) = rhs {
71
+ let size = tcx. layout_of ( param_env. and ( switch_ty) ) . unwrap ( ) . size ;
72
+ let const_cmp = Operand :: const_from_scalar (
73
+ tcx,
74
+ switch_ty,
75
+ crate :: interpret:: Scalar :: from_uint ( val, size) ,
76
+ rustc_span:: DUMMY_SP ,
77
+ ) ;
78
+ if let Some ( c) = c. literal . try_eval_bool ( tcx, param_env) {
79
+ let op = if c { BinOp :: Eq } else { BinOp :: Ne } ;
80
+ * rhs = Rvalue :: BinaryOp ( op, Operand :: Move ( discr) , const_cmp) ;
81
+ }
82
+ }
81
83
}
82
84
}
83
85
}
0 commit comments